Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/stdio/gets.c
Show All 38 Lines | |||||
#include "namespace.h" | #include "namespace.h" | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | ||||
#include "un-namespace.h" | #include "un-namespace.h" | ||||
#include "libc_private.h" | #include "libc_private.h" | ||||
#include "local.h" | #include "local.h" | ||||
__warn_references(gets, "warning: this program uses gets(), which is unsafe."); | __warn_references(gets, "warning: this program uses gets(), which is unsafe and has been disabled."); | ||||
allanjude: Is there a way to make this an #error instead of a @warn ? | |||||
char * | char * | ||||
gets(char *buf) | gets(char *buf) | ||||
{ | { | ||||
int c; | |||||
char *s, *ret; | |||||
static int warned; | |||||
static const char w[] = | |||||
"warning: this program uses gets(), which is unsafe.\n"; | |||||
FLOCKFILE_CANCELSAFE(stdin); | abort(); | ||||
ORIENT(stdin, -1); | |||||
if (!warned) { | |||||
(void) _write(STDERR_FILENO, w, sizeof(w) - 1); | |||||
warned = 1; | |||||
} | |||||
for (s = buf; (c = __sgetc(stdin)) != '\n'; ) { | |||||
if (c == EOF) | |||||
if (s == buf) { | |||||
ret = NULL; | |||||
goto end; | |||||
} else | |||||
break; | |||||
else | |||||
*s++ = c; | |||||
} | |||||
*s = 0; | |||||
ret = buf; | |||||
end: | |||||
FUNLOCKFILE_CANCELSAFE(); | |||||
return (ret); | |||||
} | } |
Is there a way to make this an #error instead of a @warn ?