Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/stdio/fread.c
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Lines | __fread(void * __restrict buf, size_t size, size_t count, FILE * __restrict fp) | ||||
* read and actually do the work. | * read and actually do the work. | ||||
*/ | */ | ||||
resid = count * size; | resid = count * size; | ||||
ORIENT(fp, -1); | ORIENT(fp, -1); | ||||
if (fp->_r < 0) | if (fp->_r < 0) | ||||
fp->_r = 0; | fp->_r = 0; | ||||
total = resid; | total = resid; | ||||
p = buf; | p = buf; | ||||
/* | |||||
* If we're unbuffered we know that the buffer in fp is empty so | |||||
* we can read directly into buf. This is much faster than a | |||||
* series of one byte reads into fp->_nbuf. | |||||
*/ | |||||
if ((fp->_flags & __SNBF) != 0 && buf != NULL) { | |||||
while (resid > 0) { | |||||
/* set up the buffer */ | |||||
fp->_bf._base = fp->_p = p; | |||||
fp->_bf._size = resid; | |||||
if (__srefill(fp)) { | |||||
/* no more input: return partial result */ | |||||
count = (total - resid) / size; | |||||
break; | |||||
} | |||||
p += fp->_r; | |||||
resid -= fp->_r; | |||||
} | |||||
/* restore the old buffer (see __smakebuf) */ | |||||
fp->_bf._base = fp->_p = fp->_nbuf; | |||||
fp->_bf._size = 1; | |||||
fp->_r = 0; | |||||
return (count); | |||||
kib: This cannot be right. | |||||
Done Inline ActionsShould it just be? FLOCKFILE_CANCELSAFE(fp); pfg: Should it just be?
```
FLOCKFILE_CANCELSAFE(fp);
``` | |||||
Done Inline ActionsI meant FUNLOCKFILE_CANCELSAFE(); but I guess one has to lock before unlocking ? pfg: I meant
```
FUNLOCKFILE_CANCELSAFE();
```
but I guess one has to lock before unlocking ? | |||||
Done Inline ActionsLook at fread() and __fread(). You patched __fread(), which assumes that the locks are taken externally and unlocked externally as well, when needed. In other words, just delete (any) unlock you added. kib: Look at `fread()` and `__fread()`. You patched `__fread()`, which assumes that the locks are… | |||||
} | |||||
while (resid > (r = fp->_r)) { | while (resid > (r = fp->_r)) { | ||||
(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; | ||||
/* 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 */ | ||||
Show All 10 Lines |
This cannot be right.