about summary refs log tree commit diff
path: root/libio
diff options
context:
space:
mode:
authorUlrich Drepper <drepper@redhat.com>2001-03-27 00:16:51 +0000
committerUlrich Drepper <drepper@redhat.com>2001-03-27 00:16:51 +0000
commit0a04075ed9766681c796dfe0f2e2fb81881f09ba (patch)
treecd119d2b35e7172478d025f98ac1da2718c723ed /libio
parent543cf8a9e162a9a812770c628fa06c7a256752ee (diff)
downloadglibc-0a04075ed9766681c796dfe0f2e2fb81881f09ba.tar.gz
glibc-0a04075ed9766681c796dfe0f2e2fb81881f09ba.tar.xz
glibc-0a04075ed9766681c796dfe0f2e2fb81881f09ba.zip
Update.
2001-03-26  Ulrich Drepper  <drepper@redhat.com>

	* libio/Makefile (tests): Add tst-ext.
	* libio/tst-ext.c: New file.

	* libio/iosetvbuf.c (_IO_setvbuf): Clear line buffer flag for _IONBF.
Diffstat (limited to 'libio')
-rw-r--r--libio/Makefile2
-rw-r--r--libio/iosetvbuf.c4
-rw-r--r--libio/tst-ext.c141
3 files changed, 145 insertions, 2 deletions
diff --git a/libio/Makefile b/libio/Makefile
index 9e13a7994d..ab2178096f 100644
--- a/libio/Makefile
+++ b/libio/Makefile
@@ -48,7 +48,7 @@ routines	:=							      \
 	libc_fatal fmemopen
 
 tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc   \
-	tst_wprintf2 tst-widetext test-fmemopen
+	tst_wprintf2 tst-widetext test-fmemopen tst-ext
 test-srcs = test-freopen
 
 all: # Make this the default target; it will be defined in Rules.
diff --git a/libio/iosetvbuf.c b/libio/iosetvbuf.c
index 673677191a..bff286b028 100644
--- a/libio/iosetvbuf.c
+++ b/libio/iosetvbuf.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1993, 96, 97, 98, 99, 2000 Free Software Foundation, Inc.
+/* Copyright (C) 1993,96,97,98,99,2000,2001 Free Software Foundation, Inc.
    This file is part of the GNU IO Library.
 
    This library is free software; you can redistribute it and/or
@@ -82,6 +82,8 @@ _IO_setvbuf (fp, buf, mode, size)
 	}
       break;
     case _IONBF:
+      fp->_IO_file_flags &= ~_IO_LINE_BUF;
+      fp->_IO_file_flags |= _IO_UNBUFFERED;
       buf = NULL;
       size = 0;
       break;
diff --git a/libio/tst-ext.c b/libio/tst-ext.c
new file mode 100644
index 0000000000..f69fbe6f21
--- /dev/null
+++ b/libio/tst-ext.c
@@ -0,0 +1,141 @@
+#include <stdio_ext.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+int
+main (void)
+{
+  FILE *fp;
+  const char teststring[] = "hello world";
+  char buf[3072];
+  int result = 0;
+  char readbuf[256];
+
+  /* Open a file.  */
+  fp = tmpfile ();
+
+  /* Set a buffer.  */
+  if (setvbuf (fp, buf, _IOFBF, sizeof buf) == EOF)
+    {
+      printf ("setvbuf failed: %m\n");
+      exit (1);
+    }
+
+  /* Get the buffer size.  */
+  if (__fbufsize (fp) != sizeof buf)
+    {
+      printf ("__fbusize() reported a buffer size of %Zd bytes;"
+	      " we installed a buffer with %Zd bytes\n",
+	      __fbufsize (fp), sizeof buf);
+      result = 1;
+    }
+
+  /* Write something and read it back.  */
+  if (fputs (teststring, fp) == EOF)
+    {
+      printf ("writing to new stream failed: %m\n");
+      exit (1);
+    }
+  rewind (fp);
+  if (fgets (readbuf, sizeof readbuf, fp) == NULL)
+    {
+      printf ("reading from new stream failed: %m\n");
+      exit (1);
+    }
+  if (strcmp (readbuf, teststring) != 0)
+    {
+      puts ("not the correct string read");
+      exit (1);
+    }
+
+  /* The file must be opened for reading and writing.  */
+  if (__freading (fp) == 0)
+    {
+      puts ("__freading() reported stream is not last read from");
+      result = 1;
+    }
+  if (__fwriting (fp) != 0)
+    {
+      puts ("__fwriting() reported stream is write-only or last written to");
+      result = 1;
+    }
+  rewind (fp);
+  if (fputs (teststring, fp) == EOF)
+    {
+      printf ("writing(2) to new stream failed: %m\n");
+      exit (1);
+    }
+  if (__fwriting (fp) == 0)
+    {
+      puts ("__fwriting() doe snot reported stream is last written to");
+      result = 1;
+    }
+  if (__freading (fp) != 0)
+    {
+      puts ("__freading() reported stream is last read from");
+      result = 1;
+    }
+
+  if (__freadable (fp) == 0)
+    {
+      puts ("__freading() reported stream is last readable");
+      result = 1;
+    }
+  if (__fwritable (fp) == 0)
+    {
+      puts ("__freading() reported stream is last writable");
+      result = 1;
+    }
+
+  /* The string we wrote above should still be in the buffer.  */
+  if (__fpending (fp) != strlen (teststring))
+    {
+      printf ("__fpending() returned %Zd; expected %Zd\n",
+	      __fpending (fp), strlen (teststring));
+      result = 1;
+    }
+  /* Discard all the output.  */
+  __fpurge (fp);
+  /* And check again.  */
+  if (__fpending (fp) != 0)
+    {
+      printf ("__fpending() returned %Zd; expected 0\n",
+	      __fpending (fp));
+      result = 1;
+    }
+
+
+  /* Find out whether buffer is line buffered.  */
+  if (__flbf (fp) != 0)
+    {
+      puts ("__flbf() reports line buffered but it is fully buffered");
+      result = 1;
+    }
+
+  if (setvbuf (fp, buf, _IOLBF, sizeof buf) == EOF)
+    {
+      printf ("setvbuf(2) failed: %m\n");
+      exit (1);
+    }
+  if (__flbf (fp) == 0)
+    {
+      puts ("__flbf() reports file is not line buffered");
+      result = 1;
+    }
+
+  if (setvbuf (fp, NULL, _IONBF, 0) == EOF)
+    {
+      printf ("setvbuf(3) failed: %m\n");
+      exit (1);
+    }
+  if (__flbf (fp) != 0)
+    {
+      puts ("__flbf() reports line buffered but it is not buffered");
+      result = 1;
+    }
+
+  fclose (fp);
+
+  return result;
+}