Loading...
--- Libc/Libc-1353.100.2/stdio/FreeBSD/fwrite.c
+++ Libc/Libc-825.26/stdio/FreeBSD/fwrite.c
@@ -44,13 +44,6 @@
#include "libc_private.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.
*/
@@ -60,10 +53,9 @@
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.
@@ -73,27 +65,20 @@
if (n == 0)
return (0);
#endif
+ iov.iov_base = (void *)buf;
+ uio.uio_resid = iov.iov_len = n;
uio.uio_iov = &iov;
uio.uio_iovcnt = 1;
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;
-
- /*
- * 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);
}