Home | History | Annotate | Download | only in libffi.call
      1 /* Area:	ffi_call
      2    Purpose:	Check stdcall strlen call on X86_WIN32 systems.
      3    Limitations:	none.
      4    PR:		none.
      5    Originator:	From the original ffitest.c  */
      6 
      7 /* { dg-do run { target i?86-*-cygwin* i?86-*-mingw* } } */
      8 
      9 #include "ffitest.h"
     10 
     11 static size_t __attribute__((stdcall)) my_stdcall_strlen(char *s)
     12 {
     13   return (strlen(s));
     14 }
     15 
     16 int main (void)
     17 {
     18   ffi_cif cif;
     19   ffi_type *args[MAX_ARGS];
     20   void *values[MAX_ARGS];
     21   ffi_arg rint;
     22   char *s;
     23   args[0] = &ffi_type_pointer;
     24   values[0] = (void*) &s;
     25 
     26   /* Initialize the cif */
     27   CHECK(ffi_prep_cif(&cif, FFI_STDCALL, 1,
     28 		       &ffi_type_sint, args) == FFI_OK);
     29 
     30   s = "a";
     31   ffi_call(&cif, FFI_FN(my_stdcall_strlen), &rint, values);
     32   CHECK(rint == 1);
     33 
     34   s = "1234567";
     35   ffi_call(&cif, FFI_FN(my_stdcall_strlen), &rint, values);
     36   CHECK(rint == 7);
     37 
     38   s = "1234567890123456789012345";
     39   ffi_call(&cif, FFI_FN(my_stdcall_strlen), &rint, values);
     40   CHECK(rint == 25);
     41 
     42   printf("stdcall strlen tests passed\n");
     43   exit(0);
     44 }
     45