Loading...
stdio/FreeBSD/fwrite.c Libc-1725.40.4 Libc-498
--- Libc/Libc-1725.40.4/stdio/FreeBSD/fwrite.c
+++ Libc/Libc-498/stdio/FreeBSD/fwrite.c
@@ -13,6 +13,10 @@
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in the
  *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *	This product includes software developed by the University of
+ *	California, Berkeley and its contributors.
  * 4. Neither the name of the University nor the names of its contributors
  *    may be used to endorse or promote products derived from this software
  *    without specific prior written permission.
@@ -34,7 +38,7 @@
 static char sccsid[] = "@(#)fwrite.c	8.1 (Berkeley) 6/4/93";
 #endif /* LIBC_SCCS and not lint */
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/lib/libc/stdio/fwrite.c,v 1.13 2009/07/12 13:09:43 ed Exp $");
+__FBSDID("$FreeBSD: src/lib/libc/stdio/fwrite.c,v 1.11 2002/10/12 16:13:41 mike Exp $");
 
 #include "namespace.h"
 #include <stdio.h>
@@ -42,61 +46,35 @@
 #include "local.h"
 #include "fvwrite.h"
 #include "libc_private.h"
-#include "libc_hooks_impl.h"
-
-/*
- * The maximum amount to write to avoid integer overflow (especially for
- * uio_resid in struct __suio).  INT_MAX is odd, so it make sense to make it
- * even.  We subtract (BUFSIZ - 1) to get a whole number of BUFSIZ chunks.
- */
-#define MAXWRITE	(INT_MAX - (BUFSIZ - 1))
 
 /*
  * Write `count' objects (each size `size') from memory to the given file.
  * Return the number of whole objects written.
  */
 size_t
-fwrite(const void * __restrict buf, size_t size, size_t count,
-    FILE * __restrict fp)
+fwrite(buf, size, count, fp)
+	const void * __restrict buf;
+	size_t size, count;
+	FILE * __restrict fp;
 {
-	size_t n, resid;
+	size_t n;
 	struct __suio uio;
 	struct __siov iov;
-	int s;
 
-	/*
-	 * ANSI and SUSv2 require a return value of 0 if size or count are 0.
-	 */
-	n = count * size;
-#if __DARWIN_UNIX03
-	if (n == 0)
-		return (0);
-#endif
+	iov.iov_base = (void *)buf;
+	uio.uio_resid = iov.iov_len = n = count * size;
 	uio.uio_iov = &iov;
 	uio.uio_iovcnt = 1;
 
-	libc_hooks_will_write(fp, sizeof(*fp));
-
 	FLOCKFILE(fp);
 	ORIENT(fp, -1);
-
-	for (resid = n; resid > 0; buf += s, resid -= s) {
-		s = resid > INT_MAX ? MAXWRITE : (int)resid;
-		iov.iov_base = (void *)buf;
-		uio.uio_resid = iov.iov_len = s;
-
-		libc_hooks_will_read(buf, s);
-
-		/*
-		 * The usual case is success (__sfvwrite returns 0);
-		 * skip the divide if this happens, since divides are
-		 * generally slow and since this occurs whenever size==0.
-		 */
-		if (__sfvwrite(fp, &uio) != 0) {
-			count = (n - resid + s - uio.uio_resid) / size;
-			break;
-		}
-	}
+	/*
+	 * The usual case is success (__sfvwrite returns 0);
+	 * skip the divide if this happens, since divides are
+	 * generally slow and since this occurs whenever size==0.
+	 */
+	if (__sfvwrite(fp, &uio) != 0)
+	    count = (n - uio.uio_resid) / size;
 	FUNLOCKFILE(fp);
 	return (count);
 }