Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/stdio/fread.c
Show All 33 Lines | |||||
#if defined(LIBC_SCCS) && !defined(lint) | #if defined(LIBC_SCCS) && !defined(lint) | ||||
static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; | static char sccsid[] = "@(#)fread.c 8.2 (Berkeley) 12/11/93"; | ||||
#endif /* LIBC_SCCS and not lint */ | #endif /* LIBC_SCCS and not lint */ | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | ||||
#include "namespace.h" | #include "namespace.h" | ||||
#include <assert.h> | |||||
#include <errno.h> | #include <errno.h> | ||||
#include <stdint.h> | #include <stdint.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include "un-namespace.h" | #include "un-namespace.h" | ||||
#include "local.h" | #include "local.h" | ||||
#include "libc_private.h" | #include "libc_private.h" | ||||
▲ Show 20 Lines • Show All 74 Lines • ▼ Show 20 Lines | if ((fp->_flags & __SNBF) != 0 && buf != NULL) { | ||||
fp->_bf._base = fp->_p = fp->_nbuf; | fp->_bf._base = fp->_p = fp->_nbuf; | ||||
fp->_bf._size = 1; | fp->_bf._size = 1; | ||||
fp->_r = 0; | fp->_r = 0; | ||||
return (count); | return (count); | ||||
} | } | ||||
while (resid > (r = fp->_r)) { | while (resid > (r = fp->_r)) { | ||||
if (fp->_p) { | |||||
(void)memcpy((void *)p, (void *)fp->_p, (size_t)r); | (void)memcpy((void *)p, (void *)fp->_p, (size_t)r); | ||||
fp->_p += r; | fp->_p += r; | ||||
} else { | |||||
assert(r == 0); | |||||
} | |||||
/* fp->_r = 0 ... done in __srefill */ | /* fp->_r = 0 ... done in __srefill */ | ||||
p += r; | p += r; | ||||
resid -= r; | resid -= r; | ||||
if (__srefill(fp)) { | if (__srefill(fp)) { | ||||
/* no more input: return partial result */ | /* no more input: return partial result */ | ||||
return ((total - resid) / size); | return ((total - resid) / size); | ||||
} | } | ||||
} | } | ||||
(void)memcpy((void *)p, (void *)fp->_p, resid); | (void)memcpy((void *)p, (void *)fp->_p, resid); | ||||
fp->_r -= resid; | fp->_r -= resid; | ||||
fp->_p += resid; | fp->_p += resid; | ||||
return (count); | return (count); | ||||
} | } | ||||
__weak_reference(__fread, fread_unlocked); | __weak_reference(__fread, fread_unlocked); |