mirror of
git://git.musl-libc.org/musl
synced 2024-12-15 11:15:07 +00:00
fix getdelim to set the error indicator on all failures
This commit is contained in:
parent
077096259d
commit
05e0e301e3
@ -13,15 +13,17 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric
|
||||
size_t i=0;
|
||||
int c;
|
||||
|
||||
FLOCK(f);
|
||||
|
||||
if (!n || !s) {
|
||||
f->flags |= F_ERR;
|
||||
FUNLOCK(f);
|
||||
errno = EINVAL;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!*s) *n=0;
|
||||
|
||||
FLOCK(f);
|
||||
|
||||
for (;;) {
|
||||
z = memchr(f->rpos, delim, f->rend - f->rpos);
|
||||
k = z ? z - f->rpos + 1 : f->rend - f->rpos;
|
||||
@ -56,6 +58,7 @@ ssize_t getdelim(char **restrict s, size_t *restrict n, int delim, FILE *restric
|
||||
|
||||
return i;
|
||||
oom:
|
||||
f->flags |= F_ERR;
|
||||
FUNLOCK(f);
|
||||
errno = ENOMEM;
|
||||
return -1;
|
||||
|
Loading…
Reference in New Issue
Block a user