2.4-6
[glibc.git] / stdio-common / tst-fmemopen2.c
blob81beddddef9cd71fcad65a9ad98de7604bf1a090
1 #include <assert.h>
2 #include <stdio.h>
3 #include <string.h>
4 #include <sys/types.h>
7 static int
8 do_test (void)
10 int result = 0;
11 char buf[100];
12 FILE *fp = fmemopen (buf, sizeof (buf), "w");
13 if (fp == NULL)
15 puts ("fmemopen failed");
16 return 0;
18 static const char str[] = "hello world";
19 #define nstr (sizeof (str) - 1)
20 fputs (str, fp);
21 off_t o = ftello (fp);
22 if (o != nstr)
24 printf ("first ftello returned %ld, expected %zu\n", o, nstr);
25 result = 1;
27 rewind (fp);
28 o = ftello (fp);
29 if (o != 0)
31 printf ("second ftello returned %ld, expected %zu\n", o, (off_t) 0);
32 result = 1;
34 if (fseeko (fp, 0, SEEK_END) != 0)
36 puts ("fseeko failed");
37 return 1;
39 o = ftello (fp);
40 if (o != nstr)
42 printf ("third ftello returned %ld, expected %zu\n", o, nstr);
43 result = 1;
45 rewind (fp);
46 static const char str2[] = "just hello";
47 #define nstr2 (sizeof (str2) - 1)
48 assert (nstr2 < nstr);
49 fputs (str2, fp);
50 o = ftello (fp);
51 if (o != nstr2)
53 printf ("fourth ftello returned %ld, expected %zu\n", o, nstr2);
54 result = 1;
56 fclose (fp);
57 static const char str3[] = "just hellod";
58 if (strcmp (buf, str3) != 0)
60 printf ("final string is \"%s\", expected \"%s\"\n",
61 buf, str3);
62 result = 1;
64 return result;
67 #define TEST_FUNCTION do_test ()
68 #include "../test-skeleton.c"