8 #include <support/xstdio.h>
11 #define THE_COOKIE ((void *) 0xdeadbeeful)
16 static int cookieread_called
;
18 cookieread (void *cookie
, char *buf
, size_t count
)
20 printf ("`%s' called with cookie %#lx\n", __FUNCTION__
,
21 (unsigned long int) cookie
);
22 if (cookie
!= THE_COOKIE
)
24 cookieread_called
= 1;
29 static int cookiewrite_called
;
31 cookiewrite (void *cookie
, const char *buf
, size_t count
)
33 printf ("`%s' called with cookie %#lx\n", __FUNCTION__
,
34 (unsigned long int) cookie
);
35 if (cookie
!= THE_COOKIE
)
37 cookiewrite_called
= 1;
42 static int cookieseek_called
;
44 cookieseek (void *cookie
, off64_t
*offset
, int whence
)
46 printf ("`%s' called with cookie %#lx\n", __FUNCTION__
,
47 (unsigned long int) cookie
);
48 if (cookie
!= THE_COOKIE
)
50 cookieseek_called
= 1;
55 static int cookieclose_called
;
57 cookieclose (void *cookie
)
59 printf ("`%s' called with cookie %#lx\n", __FUNCTION__
,
60 (unsigned long int) cookie
);
61 if (cookie
!= THE_COOKIE
)
63 cookieclose_called
= 1;
71 cookie_io_functions_t fcts
;
75 fcts
.read
= cookieread
;
76 fcts
.seek
= cookieseek
;
77 fcts
.close
= cookieclose
;
78 fcts
.write
= cookiewrite
;
80 f
= fopencookie (THE_COOKIE
, "r+", fcts
);
82 xfread (buf
, 1, 1, f
);
84 fwrite (buf
, 1, 1, f
);
85 fseek (f
, 0, SEEK_CUR
);
88 if (cookieread_called
== 0
89 || cookiewrite_called
== 0
90 || cookieseek_called
== 0
91 || cookieclose_called
== 0)
97 #define TEST_FUNCTION do_test ()
98 #include "../test-skeleton.c"