support: Add support_set_vma_name
[glibc.git] / stdio-common / tst-cookie.c
blob90ebc8e58c4b5f2348a7c3153aa7fb378a80def0
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <errno.h>
6 #include <stdio.h>
8 #include <support/xstdio.h>
11 #define THE_COOKIE ((void *) 0xdeadbeeful)
13 static int errors;
16 static int cookieread_called;
17 static ssize_t
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)
23 ++errors;
24 cookieread_called = 1;
25 return 42;
29 static int cookiewrite_called;
30 static ssize_t
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)
36 ++errors;
37 cookiewrite_called = 1;
38 return 43;
42 static int cookieseek_called;
43 static int
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)
49 ++errors;
50 cookieseek_called = 1;
51 return 44;
55 static int cookieclose_called;
56 static int
57 cookieclose (void *cookie)
59 printf ("`%s' called with cookie %#lx\n", __FUNCTION__,
60 (unsigned long int) cookie);
61 if (cookie != THE_COOKIE)
62 ++errors;
63 cookieclose_called = 1;
64 return 45;
68 static int
69 do_test (void)
71 cookie_io_functions_t fcts;
72 char buf[1];
73 FILE *f;
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);
86 fclose (f);
88 if (cookieread_called == 0
89 || cookiewrite_called == 0
90 || cookieseek_called == 0
91 || cookieclose_called == 0)
92 ++errors;
94 return errors != 0;
97 #define TEST_FUNCTION do_test ()
98 #include "../test-skeleton.c"