summaryrefslogtreecommitdiff
path: root/stdio-common/tst-fmemopen2.c
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2005-01-06 02:09:15 +0000
committerUlrich Drepper <drepper@redhat.com>2005-01-06 02:09:15 +0000
commit1b99d99f0e7e7bfc690f260d16193f162dfda8cf (patch)
tree9300dc0bf62d3c96812d67ee54c943b9af82b0f2 /stdio-common/tst-fmemopen2.c
parent1e7cceb99ec29742d8d07abfaa39718b3aed65a1 (diff)
Update.
* libio/fmemopen.c (fmemopen_seek): SEEK_END should count from maximum used address, not maximum buffer position.
Diffstat (limited to 'stdio-common/tst-fmemopen2.c')
-rw-r--r--stdio-common/tst-fmemopen2.c67
1 files changed, 67 insertions, 0 deletions
diff --git a/stdio-common/tst-fmemopen2.c b/stdio-common/tst-fmemopen2.c
new file mode 100644
index 0000000000..6a0ee836a2
--- /dev/null
+++ b/stdio-common/tst-fmemopen2.c
@@ -0,0 +1,67 @@
+#include <assert.h>
+#include <stdio.h>
+#include <sys/types.h>
+
+
+static int
+do_test (void)
+{
+ int result = 0;
+ char buf[100];
+ FILE *fp = fmemopen (buf, sizeof (buf), "w");
+ if (fp == NULL)
+ {
+ puts ("fmemopen failed");
+ return 0;
+ }
+ static const char str[] = "hello world";
+#define nstr (sizeof (str) - 1)
+ fputs (str, fp);
+ off_t o = ftello (fp);
+ if (o != nstr)
+ {
+ printf ("first ftello returned %ld, expected %zu\n", o, nstr);
+ result = 1;
+ }
+ rewind (fp);
+ o = ftello (fp);
+ if (o != 0)
+ {
+ printf ("second ftello returned %ld, expected %zu\n", o, 0);
+ result = 1;
+ }
+ if (fseeko (fp, 0, SEEK_END) != 0)
+ {
+ puts ("fseeko failed");
+ return 1;
+ }
+ o = ftello (fp);
+ if (o != nstr)
+ {
+ printf ("third ftello returned %ld, expected %zu\n", o, nstr);
+ result = 1;
+ }
+ rewind (fp);
+ static const char str2[] = "just hello";
+#define nstr2 (sizeof (str2) - 1)
+ assert (nstr2 < nstr);
+ fputs (str2, fp);
+ o = ftello (fp);
+ if (o != nstr2)
+ {
+ printf ("fourth ftello returned %ld, expected %zu\n", o, nstr2);
+ result = 1;
+ }
+ fclose (fp);
+ static const char str3[] = "just hellod";
+ if (strcmp (buf, str3) != 0)
+ {
+ printf ("final string is \"%s\", expected \"%s\"\n",
+ buf, str3);
+ result = 1;
+ }
+ return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"