Loading...
stdio/FreeBSD/fread.c Libc-1725.40.4 Libc-825.25
--- Libc/Libc-1725.40.4/stdio/FreeBSD/fread.c
+++ Libc/Libc-825.25/stdio/FreeBSD/fread.c
@@ -42,7 +42,6 @@
 #include "un-namespace.h"
 #include "local.h"
 #include "libc_private.h"
-#include "libc_hooks_impl.h"
 
 /*
  * MT-safe version
@@ -53,30 +52,29 @@
 {
 	size_t ret;
 
-	libc_hooks_will_write(fp, sizeof(*fp));
-
 	FLOCKFILE(fp);
 	ret = __fread(buf, size, count, fp);
 	FUNLOCKFILE(fp);
 	return (ret);
 }
 
-/*
- * The maximum amount to read to avoid integer overflow.  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 MAXREAD	(INT_MAX - (BUFSIZ - 1))
-
-/* __fread0: int sized, with size = 1 */
-static inline int
-__fread0(void * __restrict buf, int count, FILE * __restrict fp)
+size_t
+__fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp)
 {
-	int resid;
+	size_t resid;
 	char *p;
 	int r, ret;
+	size_t total;
 
-	resid = count;
+	/*
+	 * ANSI and SUSv2 require a return value of 0 if size or count are 0.
+	 */
+	if ((resid = count * size) == 0)
+		return (0);
+	ORIENT(fp, -1);
+	if (fp->_r < 0)
+		fp->_r = 0;
+	total = resid;
 	p = buf;
 	/* first deal with anything left in buffer, plus any ungetc buffers */
 	while (resid > (r = fp->_r)) {
@@ -89,7 +87,7 @@
 			break;
 		else if (ret) {
 			/* no more input: return partial result */
-			return (count - resid);
+			return ((total - resid) / size);
 		}
 	}
 	/*
@@ -103,7 +101,7 @@
 		size_t n;
 
 		save = fp->_bf;
-		fp->_bf._base = (unsigned char *)p;
+		fp->_bf._base = p;
 		fp->_bf._size = resid;
 		while (fp->_bf._size > 0) {
 			if ((ret = __srefill1(fp)) != 0) {
@@ -112,7 +110,7 @@
 				fp->_bf = save;
 				fp->_p = fp->_bf._base;
 				/* fp->_r = 0;  already set in __srefill1 */
-				return (count - resid);
+				return ((total - resid) / size);
 			}
 			fp->_bf._base += fp->_r;
 			fp->_bf._size -= fp->_r;
@@ -132,7 +130,7 @@
 			resid -= r;
 			if (__srefill1(fp)) {
 				/* no more input: return partial result */
-				return (count - resid);
+				return ((total - resid) / size);
 			}
 		}
 		(void)memcpy((void *)p, (void *)fp->_p, resid);
@@ -141,31 +139,3 @@
 	}
 	return (count);
 }
-
-size_t
-__fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp)
-{
-	size_t resid;
-	int r, ret;
-	size_t total;
-
-	libc_hooks_will_write(buf, size * count);
-
-	/*
-	 * ANSI and SUSv2 require a return value of 0 if size or count are 0.
-	 */
-	if ((resid = count * size) == 0)
-		return (0);
-	ORIENT(fp, -1);
-	if (fp->_r < 0)
-		fp->_r = 0;
-
-	for (total = resid; resid > 0; buf += r, resid -= r) {
-		r = resid > INT_MAX ? MAXREAD : (int)resid;
-		if ((ret = __fread0(buf, r, fp)) != r) {
-			count = (total - resid + ret) / size;
-			break;
-		}
-	}
-	return (count);
-}