X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;f=src%2Fstdio%2Fgets.c;h=17963b93e39223a031dfbd661e34160e5fe81b58;hb=68c983919ecfa75a8216d93b85baaefcb7b6e51c;hp=6c4645e5640b7b9d4df8387346a02122dfc0f5ea;hpb=835f9f950e2f6059532bd9ab9857a856ed21a4fd;p=musl diff --git a/src/stdio/gets.c b/src/stdio/gets.c index 6c4645e5..17963b93 100644 --- a/src/stdio/gets.c +++ b/src/stdio/gets.c @@ -4,7 +4,12 @@ char *gets(char *s) { - char *ret = fgets(s, INT_MAX, stdin); - if (ret && s[strlen(s)-1] == '\n') s[strlen(s)-1] = 0; - return ret; + size_t i=0; + int c; + FLOCK(stdin); + while ((c=getc_unlocked(stdin)) != EOF && c != '\n') s[i++] = c; + s[i] = 0; + if (c != '\n' && (!feof(stdin) || !i)) s = 0; + FUNLOCK(stdin); + return s; }