summaryrefslogtreecommitdiff
path: root/stdio-common
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2005-01-06 14:57:16 +0000
committerJakub Jelinek <jakub@redhat.com>2005-01-06 14:57:16 +0000
commit0ecfa2580d1aedb744deb5af1b60f92c69b9e9e0 (patch)
tree1ef0d0dc09dba23037800d5f3794a77d9b45554f /stdio-common
parente4f5d077e9190f57abd49684bd7afcf4325bd348 (diff)
Updated to fedora-glibc-20050106T1443
Diffstat (limited to 'stdio-common')
-rw-r--r--stdio-common/Makefile4
-rw-r--r--stdio-common/tst-fmemopen2.c67
2 files changed, 69 insertions, 2 deletions
diff --git a/stdio-common/Makefile b/stdio-common/Makefile
index 3a66f1d021..2e797e4dfe 100644
--- a/stdio-common/Makefile
+++ b/stdio-common/Makefile
@@ -1,4 +1,4 @@
-# Copyright (C) 1991-2002, 2003, 2004 Free Software Foundation, Inc.
+# Copyright (C) 1991-2002, 2003, 2004, 2005 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
@@ -53,7 +53,7 @@ tests := tstscanf test_rdwr test-popen tstgetln test-fseek \
scanf11 scanf12 tst-tmpnam tst-cookie tst-obprintf tst-sscanf \
tst-swprintf tst-fseek tst-fmemopen test-vfprintf tst-gets \
tst-perror tst-sprintf tst-rndseek tst-fdopen tst-fphex bug14 bug15 \
- tst-popen tst-unlockedio
+ tst-popen tst-unlockedio tst-fmemopen2
test-srcs = tst-unbputc tst-printf
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"