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 /* UNSAFE FUNCTION -- do not bother optimizing */
11 
12 /* disable macro, force actual function call */
13 #undef getchar_unlocked
14 
gets(char * s)15 char *gets(char *s)
16 {
17 	register char *p = s;
18 	int c;
19 	__STDIO_AUTO_THREADLOCK_VAR;
20 
21 	__STDIO_AUTO_THREADLOCK(stdin);
22 
23 	/* Note: don't worry about performance here... this shouldn't be used!
24 	 * Therefore, force actual function call. */
25 	while (((c = getchar_unlocked()) != EOF) && ((*p = c) != '\n')) {
26 		++p;
27 	}
28 	if ((c == EOF) || (s == p)) {
29 		s = NULL;
30 	} else {
31 		*p = 0;
32 	}
33 
34 	__STDIO_AUTO_THREADUNLOCK(stdin);
35 
36 	return s;
37 }
38