]>
Commit | Line | Data |
---|---|---|
0ecb606c JJ |
1 | #include <assert.h> |
2 | #include <stdio.h> | |
3 | #include <string.h> | |
4 | #include <sys/types.h> | |
5 | ||
6 | ||
7 | static int | |
8 | do_test (void) | |
9 | { | |
10 | int result = 0; | |
11 | char buf[100]; | |
12 | FILE *fp = fmemopen (buf, sizeof (buf), "w"); | |
13 | if (fp == NULL) | |
14 | { | |
15 | puts ("fmemopen failed"); | |
16 | return 0; | |
17 | } | |
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) | |
23 | { | |
24 | printf ("first ftello returned %ld, expected %zu\n", o, nstr); | |
25 | result = 1; | |
26 | } | |
27 | rewind (fp); | |
28 | o = ftello (fp); | |
29 | if (o != 0) | |
30 | { | |
31 | printf ("second ftello returned %ld, expected %zu\n", o, (off_t) 0); | |
32 | result = 1; | |
33 | } | |
34 | if (fseeko (fp, 0, SEEK_END) != 0) | |
35 | { | |
36 | puts ("fseeko failed"); | |
37 | return 1; | |
38 | } | |
39 | o = ftello (fp); | |
40 | if (o != nstr) | |
41 | { | |
42 | printf ("third ftello returned %ld, expected %zu\n", o, nstr); | |
43 | result = 1; | |
44 | } | |
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) | |
52 | { | |
53 | printf ("fourth ftello returned %ld, expected %zu\n", o, nstr2); | |
54 | result = 1; | |
55 | } | |
56 | fclose (fp); | |
57 | static const char str3[] = "just hellod"; | |
58 | if (strcmp (buf, str3) != 0) | |
59 | { | |
60 | printf ("final string is \"%s\", expected \"%s\"\n", | |
61 | buf, str3); | |
62 | result = 1; | |
63 | } | |
64 | return result; | |
65 | } | |
66 | ||
67 | #define TEST_FUNCTION do_test () | |
68 | #include "../test-skeleton.c" |