10 FILE *fp
= open_memstream (&buf
, &size
);
13 puts ("open_memstream failed");
17 off64_t off
= ftello64 (fp
);
20 puts ("initial position wrong");
24 if (fseek (fp
, 32768, SEEK_SET
) != 0)
26 puts ("fseek failed");
30 if (fputs ("foo", fp
) == EOF
)
32 puts ("fputs failed");
36 if (fclose (fp
) == EOF
)
38 puts ("fclose failed");
42 if (size
!= 32768 + 3)
44 printf ("expected size %d, got %zu\n", 32768 + 3, size
);
48 for (int i
= 0; i
< 32768; ++i
)
51 printf ("byte at offset %d is %#hhx\n", i
, buf
[i
]);
55 if (memcmp (buf
+ 32768, "foo", 3) != 0)
57 puts ("written string incorrect");
61 /* Mark the buffer. */
62 memset (buf
, 'A', size
);
65 /* Try again, this time with write mode enabled before the seek. */
66 fp
= open_memstream (&buf
, &size
);
69 puts ("2nd open_memstream failed");
76 puts ("2nd initial position wrong");
80 if (fputs ("bar", fp
) == EOF
)
82 puts ("2nd fputs failed");
86 if (fseek (fp
, 32768, SEEK_SET
) != 0)
88 puts ("2nd fseek failed");
92 if (fputs ("foo", fp
) == EOF
)
94 puts ("3rd fputs failed");
98 if (fclose (fp
) == EOF
)
100 puts ("2nd fclose failed");
104 if (size
!= 32768 + 3)
106 printf ("2nd expected size %d, got %zu\n", 32768 + 3, size
);
110 if (memcmp (buf
, "bar", 3) != 0)
112 puts ("initial string incorrect in 2nd try");
116 for (int i
= 3; i
< 32768; ++i
)
119 printf ("byte at offset %d is %#hhx in 2nd try\n", i
, buf
[i
]);
123 if (memcmp (buf
+ 32768, "foo", 3) != 0)
125 puts ("written string incorrect in 2nd try");
132 #define TEST_FUNCTION do_test ()
133 #include "../test-skeleton.c"