summaryrefslogtreecommitdiff
path: root/src/stdio/fgets.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/stdio/fgets.c')
-rw-r--r--src/stdio/fgets.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/stdio/fgets.c b/src/stdio/fgets.c
index cf5b1039..d3f9819e 100644
--- a/src/stdio/fgets.c
+++ b/src/stdio/fgets.c
@@ -10,14 +10,16 @@ char *fgets(char *restrict s, int n, FILE *restrict f)
size_t k;
int c;
+ FLOCK(f);
+
if (n--<=1) {
+ f->mode |= f->mode-1;
+ FUNLOCK(f);
if (n) return 0;
*s = 0;
return s;
}
- FLOCK(f);
-
while (n) {
z = memchr(f->rpos, '\n', f->rend - f->rpos);
k = z ? z - f->rpos + 1 : f->rend - f->rpos;