projects
/
musl
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
remove or make static various unused __-prefixed symbols
[musl]
/
src
/
stdio
/
fgets.c
diff --git
a/src/stdio/fgets.c
b/src/stdio/fgets.c
index
ee0ac30
..
d3f9819
100644
(file)
--- a/
src/stdio/fgets.c
+++ b/
src/stdio/fgets.c
@@
-1,4
+1,5
@@
#include "stdio_impl.h"
#include "stdio_impl.h"
+#include <string.h>
#define MIN(a,b) ((a)<(b) ? (a) : (b))
#define MIN(a,b) ((a)<(b) ? (a) : (b))
@@
-9,14
+10,16
@@
char *fgets(char *restrict s, int n, FILE *restrict f)
size_t k;
int c;
size_t k;
int c;
+ FLOCK(f);
+
if (n--<=1) {
if (n--<=1) {
+ f->mode |= f->mode-1;
+ FUNLOCK(f);
if (n) return 0;
*s = 0;
return s;
}
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;
while (n) {
z = memchr(f->rpos, '\n', f->rend - f->rpos);
k = z ? z - f->rpos + 1 : f->rend - f->rpos;
@@
-33,7
+36,7
@@
char *fgets(char *restrict s, int n, FILE *restrict f)
n--;
if ((*p++ = c) == '\n') break;
}
n--;
if ((*p++ = c) == '\n') break;
}
- *p = 0;
+
if (s)
*p = 0;
FUNLOCK(f);
FUNLOCK(f);