X-Git-Url: http://nsz.repo.hu/git/?a=blobdiff_plain;ds=sidebyside;f=src%2Fstdio%2Fgets.c;h=17963b93e39223a031dfbd661e34160e5fe81b58;hb=5690668a1bb9f551bb78d825bc804dcebe84b7e7;hp=24319eb2dcf62b431648bfef6641b2eda5854476;hpb=0b44a0315b47dd8eced9f3b7f31580cf14bbfc01;p=musl diff --git a/src/stdio/gets.c b/src/stdio/gets.c index 24319eb2..17963b93 100644 --- a/src/stdio/gets.c +++ b/src/stdio/gets.c @@ -1,8 +1,15 @@ #include "stdio_impl.h" +#include +#include 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; }