1 /* Copyright (C) 2004 Manuel Novoa III <mjn3@codepoet.org> 2 * 3 * GNU Library General Public License (LGPL) version 2 or later. 4 * 5 * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details. 6 */ 7 8 #include "_stdio.h" 9 10 link_warning(gets, "the 'gets' function is dangerous and should not be used.") 11 12 /* UNSAFE FUNCTION -- do not bother optimizing */ 13 14 /* disable macro, force actual function call */ 15 #undef getchar_unlocked 16 gets(char * s)17char *gets(char *s) 18 { 19 register char *p = s; 20 int c; 21 __STDIO_AUTO_THREADLOCK_VAR; 22 23 __STDIO_AUTO_THREADLOCK(stdin); 24 25 /* Note: don't worry about performance here... this shouldn't be used! 26 * Therefore, force actual function call. */ 27 while (((c = getchar_unlocked()) != EOF) && ((*p = c) != '\n')) { 28 ++p; 29 } 30 if ((c == EOF) || (s == p)) { 31 s = NULL; 32 } else { 33 *p = 0; 34 } 35 36 __STDIO_AUTO_THREADUNLOCK(stdin); 37 38 return s; 39 } 40