11 FILE *fp
= open_memstream (&buf
, &size
);
14 puts ("open_memstream failed");
18 off64_t off
= ftello64 (fp
);
21 puts ("initial position wrong");
25 if (fseek (fp
, 32768, SEEK_SET
) != 0)
27 puts ("fseek failed");
31 if (fputs ("foo", fp
) == EOF
)
33 puts ("fputs failed");
37 if (fclose (fp
) == EOF
)
39 puts ("fclose failed");
43 if (size
!= 32768 + 3)
45 printf ("expected size %d, got %zu\n", 32768 + 3, size
);
49 for (int i
= 0; i
< 32768; ++i
)
52 printf ("byte at offset %d is %#hhx\n", i
, buf
[i
]);
56 if (memcmp (buf
+ 32768, "foo", 3) != 0)
58 puts ("written string incorrect");
62 /* Mark the buffer. */
63 memset (buf
, 'A', size
);
66 /* Try again, this time with write mode enabled before the seek. */
67 fp
= open_memstream (&buf
, &size
);
70 puts ("2nd open_memstream failed");
77 puts ("2nd initial position wrong");
81 if (fputs ("bar", fp
) == EOF
)
83 puts ("2nd fputs failed");
87 if (fseek (fp
, 32768, SEEK_SET
) != 0)
89 puts ("2nd fseek failed");
93 if (fputs ("foo", fp
) == EOF
)
95 puts ("3rd fputs failed");
99 if (fclose (fp
) == EOF
)
101 puts ("2nd fclose failed");
105 if (size
!= 32768 + 3)
107 printf ("2nd expected size %d, got %zu\n", 32768 + 3, size
);
111 if (memcmp (buf
, "bar", 3) != 0)
113 puts ("initial string incorrect in 2nd try");
117 for (int i
= 3; i
< 32768; ++i
)
120 printf ("byte at offset %d is %#hhx in 2nd try\n", i
, buf
[i
]);
124 if (memcmp (buf
+ 32768, "foo", 3) != 0)
126 puts ("written string incorrect in 2nd try");
133 #define TEST_FUNCTION do_test ()
134 #include "../test-skeleton.c"