From ca22ff9ec789c21f8ac42f977f2e092b77ebe264 Mon Sep 17 00:00:00 2001 From: Joerg Wunsch Date: Wed, 27 Dec 1995 23:23:43 +0000 Subject: [PATCH] Kill the (hopefully) last occurance of gets(3) in the base source tree. --- usr.bin/tftp/main.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c index c69195dafbca..b34ab2c2f0cd 100644 --- a/usr.bin/tftp/main.c +++ b/usr.bin/tftp/main.c @@ -195,7 +195,7 @@ setpeer(argc, argv) if (argc < 2) { strcpy(line, "Connect "); printf("(to) "); - gets(&line[strlen(line)]); + fgets(&line[strlen(line)], sizeof line - strlen(line), stdin); makeargv(); argc = margc; argv = margv; @@ -323,7 +323,7 @@ put(argc, argv) if (argc < 2) { strcpy(line, "send "); printf("(file) "); - gets(&line[strlen(line)]); + fgets(&line[strlen(line)], sizeof line - strlen(line), stdin); makeargv(); argc = margc; argv = margv; @@ -417,7 +417,7 @@ get(argc, argv) if (argc < 2) { strcpy(line, "get "); printf("(files) "); - gets(&line[strlen(line)]); + fgets(&line[strlen(line)], sizeof line - strlen(line), stdin); makeargv(); argc = margc; argv = margv; @@ -501,7 +501,7 @@ setrexmt(argc, argv) if (argc < 2) { strcpy(line, "Rexmt-timeout "); printf("(value) "); - gets(&line[strlen(line)]); + fgets(&line[strlen(line)], sizeof line - strlen(line), stdin); makeargv(); argc = margc; argv = margv; @@ -529,7 +529,7 @@ settimeout(argc, argv) if (argc < 2) { strcpy(line, "Maximum-timeout "); printf("(value) "); - gets(&line[strlen(line)]); + fgets(&line[strlen(line)], sizeof line - strlen(line), stdin); makeargv(); argc = margc; argv = margv; @@ -593,16 +593,19 @@ static __dead void command() { register struct cmd *c; + char *cp; for (;;) { printf("%s> ", prompt); - if (gets(line) == 0) { + if (fgets(line, sizeof line , stdin) == 0) { if (feof(stdin)) { exit(0); } else { continue; } } + if ((cp = strchr(line, '\n'))) + *cp = '\0'; if (line[0] == 0) continue; makeargv(); @@ -660,6 +663,8 @@ makeargv() register char **argp = margv; margc = 0; + if ((cp = strchr(line, '\n'))) + *cp = '\0'; for (cp = line; *cp;) { while (isspace(*cp)) cp++;