about summary refs log tree commit diff
path: root/stdio/fwrite.c
diff options
context:
space:
mode:
authorRoland McGrath <roland@gnu.org>1996-07-03 18:51:10 +0000
committerRoland McGrath <roland@gnu.org>1996-07-03 18:51:10 +0000
commit8a594e3cb7ea389cec5043cfcfd865d2bd0b8138 (patch)
tree935db58a3859f00a437f60fe675b1748834eee00 /stdio/fwrite.c
parentf0585c83b2b70f4fb04c4c2f3611b2a5150cd888 (diff)
downloadglibc-8a594e3cb7ea389cec5043cfcfd865d2bd0b8138.tar.gz
glibc-8a594e3cb7ea389cec5043cfcfd865d2bd0b8138.tar.xz
glibc-8a594e3cb7ea389cec5043cfcfd865d2bd0b8138.zip
Wed Jul 3 11:26:28 1996 Roland McGrath <roland@delasyd.gnu.ai.mit.edu>
	* time/strftime.c (strftime: do_number): Adjust P and I after sprintf
	in case it wrote fewer than MAXDIGITS chars.

	* stdio/fwrite.c (fwrite: fill_buffer): Separate flushing for last
	newline from flushing full buffer in loop, fix test so no fflush is
	done when last byte written exactly fills the buffer.

	* nss/Makefile ($(services:%=$(objpfx)libnss_%.so)): Depend on libc.so.

	* sysdeps/mach/hurd/Makefile (LDLIBS-c.so): Variable removed.
	(libc.so): Instead, give this deps on lib{mach,hurd}user.so.

	* elf/dl-debug.c (_dl_debug_initialize): Use LDBASE arg instead of
	extracting _dl_rtld_map.l_addr.

	* sysdeps/i386/dl-machine.h (elf_machine_rel): Declare _dl_rtld_map as
	weak.
	* sysdeps/alpha/dl-machine.h (elf_machine_rela): Likewise.

	* shlib-versions (*-*-*): Set libnss_db=1.

	* elf/rtld.c (dl_main): Set _dl_rtld_map's DT_DEBUG location too.
Diffstat (limited to 'stdio/fwrite.c')
-rw-r--r--stdio/fwrite.c113
1 files changed, 62 insertions, 51 deletions
diff --git a/stdio/fwrite.c b/stdio/fwrite.c
index 4d012f1779..790c663aea 100644
--- a/stdio/fwrite.c
+++ b/stdio/fwrite.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc.
+/* Copyright (C) 1991, 1992, 1993, 1994, 1996 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
@@ -126,56 +126,67 @@ DEFUN(fwrite, (ptr, size, nmemb, stream),
 	}
     }
   else if (!default_func || buffer_space >= to_write)
-  fill_buffer:
-    /* There is enough room in the buffer for everything we
-       want to write or the user has specified his own output
-       buffer-flushing/expanding function.  */
-    while (to_write > 0)
-      {
-	register size_t n = to_write;
-
-	if (n > buffer_space)
-	  n = buffer_space;
-
-	buffer_space -= n;
-
-	written += n;
-	to_write -= n;
-
-	if (n < 20)
-	  while (n-- > 0)
-	    *stream->__bufp++ = *p++;
-	else
-	  {
-	    memcpy ((PTR) stream->__bufp, (PTR) p, n);
-	    stream->__bufp += n;
-	    p += n;
-	  }
-
-	if (buffer_space == 0 || (to_write == 0 && newlinep))
-	  {
-	    /* We've filled the buffer, so flush it.  */
-	    if (fflush (stream) == EOF)
-	      break;
-
-	    /* Reset our record of the space available in the buffer,
-	       since we have just flushed it.  */
-	  check_space:
-	    buffer_space = (stream->__bufsize -
-			    (stream->__bufp - stream->__buffer));
-	    if (buffer_space == 0)
-	      {
-		/* With a custom output-room function, flushing might
-		   not create any buffer space.  Try writing a single
-		   character to create the space.  */
-		if (__flshfp (stream, *p++) == EOF)
-		  goto done;
-		++written;
-		--to_write;
-		goto check_space;
-	      }
-	  }
-      }
+    {
+      /* There is enough room in the buffer for everything we want to write
+	 or the user has specified his own output buffer-flushing/expanding
+	 function.  */
+    fill_buffer:
+      while (to_write > 0)
+	{
+	  register size_t n = to_write;
+
+	  if (n > buffer_space)
+	    n = buffer_space;
+
+	  buffer_space -= n;
+
+	  written += n;
+	  to_write -= n;
+
+	  if (n < 20)
+	    while (n-- > 0)
+	      *stream->__bufp++ = *p++;
+	  else
+	    {
+	      memcpy ((PTR) stream->__bufp, (PTR) p, n);
+	      stream->__bufp += n;
+	      p += n;
+	    }
+
+	  if (to_write == 0)
+	    /* Done writing.  */
+	    break;
+	  else if (buffer_space == 0)
+	    {
+	      /* We have filled the buffer, so flush it.  */
+	      if (fflush (stream) == EOF)
+		break;
+
+	      /* Reset our record of the space available in the buffer,
+		 since we have just flushed it.  */
+	    check_space:
+	      buffer_space = (stream->__bufsize -
+			      (stream->__bufp - stream->__buffer));
+	      if (buffer_space == 0)
+		{
+		  /* With a custom output-room function, flushing might
+		     not create any buffer space.  Try writing a single
+		     character to create the space.  */
+		  if (__flshfp (stream, *p++) == EOF)
+		    goto done;
+		  ++written;
+		  --to_write;
+		  goto check_space;
+		}
+	    }
+	}
+
+      /* We have written all the data into the buffer.  If we are
+	 line-buffered and just put a newline in the buffer, flush now to
+	 make sure it gets out.  */
+      if (newlinep)
+	fflush (stream);
+    }
   else
     {
       /* It won't all fit in the buffer.  */