Remove non-standard gets_safe()

This commit is contained in:
Mark
2020-07-02 21:09:37 +03:00
parent 3973b10a6b
commit 2ed97a87be
2 changed files with 14 additions and 7 deletions
+1
View File
@@ -3,6 +3,7 @@ CFLAGS?=-ggdb \
-O0 \
-Wall \
-Werror \
-Wno-char-subscripts \
-Iinclude
LDFLAGS?=-lgcc
+13 -7
View File
@@ -91,16 +91,16 @@ static void signal_handle(int signum) {
}
int main(int argc, char **argv) {
int fd = STDIN_FILENO;
FILE *fp = stdin;
char linebuf[256];
int res;
signal(SIGINT, signal_handle);
if (argc == 2) {
fd = open(argv[1], O_RDONLY, 0);
fp = fopen(argv[1], "r");
if (fd < 0) {
if (!fp) {
perror(argv[1]);
return -1;
}
@@ -109,15 +109,21 @@ int main(int argc, char **argv) {
return -1;
}
int fd = fileno(fp);
// TODO: source /etc/profile?
setenv("PATH", "/sbin:/bin", 0);
if (!isatty(fd)) {
while (1) {
// TODO: use fgets here
//if (gets_safe(fd, linebuf, sizeof(linebuf)) < 0) {
// break;
//}
if (!fgets(linebuf, sizeof(linebuf), fp)) {
break;
}
char *p;
if (*linebuf && (p = strchr(linebuf, '\n')) != NULL) {
*p = 0;
}
eval(linebuf);
}