PowerPC: Fix compiler warnings
[glibc.git] / stdio-common / tst-cookie.c
blobdcdabf32308e0da91eed5939de508402a685781d
1 #include <sys/types.h>
2 #include <sys/stat.h>
3 #include <fcntl.h>
4 #include <errno.h>
6 #include <stdio.h>
9 #define THE_COOKIE ((void *) 0xdeadbeeful)
11 static int errors;
14 static int cookieread_called;
15 static ssize_t
16 cookieread (void *cookie, char *buf, size_t count)
18 printf ("`%s' called with cookie %#lx\n", __FUNCTION__,
19 (unsigned long int) cookie);
20 if (cookie != THE_COOKIE)
21 ++errors;
22 cookieread_called = 1;
23 return 42;
27 static int cookiewrite_called;
28 static ssize_t
29 cookiewrite (void *cookie, const char *buf, size_t count)
31 printf ("`%s' called with cookie %#lx\n", __FUNCTION__,
32 (unsigned long int) cookie);
33 if (cookie != THE_COOKIE)
34 ++errors;
35 cookiewrite_called = 1;
36 return 43;
40 static int cookieseek_called;
41 static int
42 cookieseek (void *cookie, off64_t *offset, int whence)
44 printf ("`%s' called with cookie %#lx\n", __FUNCTION__,
45 (unsigned long int) cookie);
46 if (cookie != THE_COOKIE)
47 ++errors;
48 cookieseek_called = 1;
49 return 44;
53 static int cookieclose_called;
54 static int
55 cookieclose (void *cookie)
57 printf ("`%s' called with cookie %#lx\n", __FUNCTION__,
58 (unsigned long int) cookie);
59 if (cookie != THE_COOKIE)
60 ++errors;
61 cookieclose_called = 1;
62 return 45;
66 int
67 main (void)
69 cookie_io_functions_t fcts;
70 char buf[1];
71 FILE *f;
73 fcts.read = cookieread;
74 fcts.seek = cookieseek;
75 fcts.close = cookieclose;
76 fcts.write = cookiewrite;
78 f = fopencookie (THE_COOKIE, "r+", fcts);
80 fread (buf, 1, 1, f);
81 fwrite (buf, 1, 1, f);
82 fseek (f, 0, SEEK_CUR);
83 fclose (f);
85 if (cookieread_called == 0
86 || cookiewrite_called == 0
87 || cookieseek_called == 0
88 || cookieclose_called == 0)
89 ++errors;
91 return errors != 0;