summaryrefslogtreecommitdiff
path: root/libio
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2002-08-27 06:41:29 +0000
committerUlrich Drepper <drepper@redhat.com>2002-08-27 06:41:29 +0000
commitb50f38778c306b3f0ec0c3ed05acf9ce10508aa4 (patch)
treefb5b26cc02ec01c04f8573a2103b11c412aab6fc /libio
parent38325923950d9dbdad735aa4bc8ce54977ef572c (diff)
downloadglibc-b50f38778c306b3f0ec0c3ed05acf9ce10508aa4.tar.gz
Update.
2002-08-26 Ulrich Drepper <drepper@redhat.com> * libio/Makefile (tests): Add bug-fopena+. * libio/bug-fopena+.c: New file. * stdio-common/tst-swprintf.c (main): Add casts to avoid warnings. * locale/xlocale.c: Fix the last change. The variable still has to end in _data. * sysdeps/generic/bits/libc-tsd.h [!(USE_TLS && HAVE___THREAD)] (__libc_tsd_set): Add _data prefix to variable name.
Diffstat (limited to 'libio')
-rw-r--r--libio/Makefile2
-rw-r--r--libio/bug-fopena+.c100
2 files changed, 101 insertions, 1 deletions
diff --git a/libio/Makefile b/libio/Makefile
index a6d3a24cc1..72a6badabd 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -53,7 +53,7 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \
tst-mmap-setvbuf bug-ungetwc1 bug-ungetwc2 tst-atime tst-eof \
tst-freopen bug-rewind bug-rewind2 bug-ungetc bug-fseek \
tst-mmap-eofsync tst-mmap-fflushsync bug-mmap-fflush \
- tst-mmap2-eofsync tst-mmap-offend
+ tst-mmap2-eofsync tst-mmap-offend bug-fopena+
test-srcs = test-freopen
all: # Make this the default target; it will be defined in Rules.
diff --git a/libio/bug-fopena+.c b/libio/bug-fopena+.c
new file mode 100644
index 0000000000..5446de1592
--- /dev/null
+++ b/libio/bug-fopena+.c
@@ -0,0 +1,100 @@
+#include <fcntl.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+static int fd;
+static char *fname;
+
+
+static void prepare (void);
+#define PREPARE(argc, argv) prepare ()
+
+
+#define TEST_FUNCTION do_test ()
+static int do_test (void);
+#include "../test-skeleton.c"
+
+
+static void
+prepare (void)
+{
+ fd = create_temp_file ("wrewind.", &fname);
+ if (fd == -1)
+ exit (3);
+}
+
+
+static int
+do_test (void)
+{
+ char buf[100];
+ FILE *fp;
+ int result = 0;
+
+ fp = fdopen (fd, "w");
+ if (fp == NULL)
+ {
+ puts ("cannot create file");
+ exit (1);
+ }
+
+ if (fputs ("one\n", fp) == EOF || fputs ("two\n", fp) == EOF)
+ {
+ puts ("cannot create filec content");
+ exit (1);
+ }
+
+ fclose (fp);
+
+ fp = fopen (fname, "a+");
+ if (fp == NULL)
+ {
+ puts ("cannot fopen a+");
+ exit (1);
+ }
+
+ if (fgets (buf, sizeof (buf), fp) == NULL)
+ {
+ puts ("cannot read after fopen a+");
+ exit (1);
+ }
+
+ if (strcmp (buf, "one\n") != 0)
+ {
+ puts ("read after fopen a+ produced wrong result");
+ result = 1;
+ }
+
+ fclose (fp);
+
+ fd = open (fname, O_RDWR);
+ if (fd == -1)
+ {
+ puts ("open failed");
+ exit (1);
+ }
+
+ fp = fdopen (fd, "a+");
+ if (fp == NULL)
+ {
+ puts ("fopen after open failed");
+ exit (1);
+ }
+
+ if (fgets (buf, sizeof (buf), fp) == NULL)
+ {
+ puts ("cannot read after fdopen a+");
+ exit (1);
+ }
+
+ if (strcmp (buf, "one\n") != 0)
+ {
+ puts ("read after fdopen a+ produced wrong result");
+ result = 1;
+ }
+
+ fclose (fp);
+
+ return result;
+}