Remove socket.S implementation
[glibc.git] / stdio-common / tst-fmemopen2.c
blobe9d8b634feb37b1758cce1c7d78c9c8af58b0968
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 %jd, expected %zu\n",
25 (intmax_t) o, nstr);
26 result = 1;
28 rewind (fp);
29 o = ftello (fp);
30 if (o != 0)
32 printf ("second ftello returned %jd, expected 0\n", (intmax_t) o);
33 result = 1;
35 if (fseeko (fp, 0, SEEK_END) != 0)
37 puts ("fseeko failed");
38 return 1;
40 o = ftello (fp);
41 if (o != nstr)
43 printf ("third ftello returned %jd, expected %zu\n",
44 (intmax_t) o, nstr);
45 result = 1;
47 rewind (fp);
48 static const char str2[] = "just hello";
49 #define nstr2 (sizeof (str2) - 1)
50 assert (nstr2 < nstr);
51 fputs (str2, fp);
52 o = ftello (fp);
53 if (o != nstr2)
55 printf ("fourth ftello returned %jd, expected %zu\n",
56 (intmax_t) o, nstr2);
57 result = 1;
59 fclose (fp);
60 static const char str3[] = "just hellod";
61 if (strcmp (buf, str3) != 0)
63 printf ("final string is \"%s\", expected \"%s\"\n",
64 buf, str3);
65 result = 1;
67 return result;
70 #define TEST_FUNCTION do_test ()
71 #include "../test-skeleton.c"