Page MenuHomeFreeBSD

D57072.id178040.diff
No OneTemporary

D57072.id178040.diff

diff --git a/usr.bin/tftp/main.c b/usr.bin/tftp/main.c
--- a/usr.bin/tftp/main.c
+++ b/usr.bin/tftp/main.c
@@ -62,7 +62,6 @@
#include "tftp-options.h"
#include "tftp.h"
-#define MAXLINE (2 * MAXPATHLEN)
#define TIMEOUT 5 /* secs between rexmt's */
typedef struct sockaddr_storage peeraddr;
@@ -336,12 +335,13 @@
static void
setpeer(int argc, char *argv[])
{
- char line[MAXLINE];
+ static char *line;
+ static size_t sz;
if (argc < 2) {
strcpy(line, "Connect ");
printf("(to) ");
- fgets(&line[strlen(line)], sizeof line - strlen(line), stdin);
+ getline(&line, &sz, stdin);
makeargv(line);
argc = margc;
argv = margv;
@@ -420,16 +420,16 @@
static void
put(int argc, char *argv[])
{
- int fd;
- int n;
- char *cp, *targ, *path;
- char line[MAXLINE];
+ static char *line;
+ static size_t sz;
+ int fd, n;
+ char *cp, *targ, *path;
struct stat sb;
if (argc < 2) {
strcpy(line, "send ");
printf("(file) ");
- fgets(&line[strlen(line)], sizeof line - strlen(line), stdin);
+ getline(&line, &sz, stdin);
makeargv(line);
argc = margc;
argv = margv;
@@ -530,16 +530,15 @@
static void
get(int argc, char *argv[])
{
- int fd;
- int n;
- char *cp;
- char *src;
- char line[MAXLINE];
+ static char *line;
+ static size_t sz;
+ int fd, n;
+ char *cp, *src;
if (argc < 2) {
strcpy(line, "get ");
printf("(files) ");
- fgets(&line[strlen(line)], sizeof line - strlen(line), stdin);
+ getline(&line, &sz, stdin);
makeargv(line);
argc = margc;
argv = margv;
@@ -620,13 +619,14 @@
static void
settimeoutpacket(int argc, char *argv[])
{
+ static char *line;
+ static size_t sz;
int t;
- char line[MAXLINE];
if (argc < 2) {
strcpy(line, "Packet timeout ");
printf("(value) ");
- fgets(&line[strlen(line)], sizeof line - strlen(line), stdin);
+ getline(&line, &sz, stdin);
makeargv(line);
argc = margc;
argv = margv;
@@ -647,13 +647,14 @@
static void
settimeoutnetwork(int argc, char *argv[])
{
+ static char *line;
+ static size_t sz;
int t;
- char line[MAXLINE];
if (argc < 2) {
strcpy(line, "Network timeout ");
printf("(value) ");
- fgets(&line[strlen(line)], sizeof line - strlen(line), stdin);
+ getline(&line, &sz, stdin);
makeargv(line);
argc = margc;
argv = margv;
@@ -730,23 +731,22 @@
static void
command(bool interactive, EditLine *el, History *hist, HistEvent *hep)
{
+ static char *line;
+ static size_t sz;
const struct cmd *c;
const char *bp;
- char *cp;
- int len, num;
- char line[MAXLINE];
+ int len;
for (;;) {
if (interactive) {
- if ((bp = el_gets(el, &num)) == NULL || num == 0)
+ if ((bp = el_gets(el, &len)) == NULL || len == 0)
exit(0);
- len = MIN(MAXLINE, num);
- memcpy(line, bp, len);
- line[len - 1] = '\0';
- history(hist, hep, H_ENTER, bp);
+ if ((size_t)len >= sz)
+ line = realloc(line, sz = len + 1);
+ strlcpy(line, bp, sz);
+ history(hist, hep, H_ENTER, line);
} else {
- line[0] = 0;
- if (fgets(line, sizeof line , stdin) == NULL) {
+ if ((len = getline(&line, &sz, stdin)) <= 0) {
if (feof(stdin)) {
exit(txrx_error);
} else {
@@ -754,8 +754,8 @@
}
}
}
- if ((cp = strchr(line, '\n')))
- *cp = '\0';
+ if (line[len - 1] == '\n')
+ line[--len] = '\0';
if (line[0] == 0)
continue;
makeargv(line);

File Metadata

Mime Type
text/plain
Expires
Sun, May 24, 12:08 AM (4 h, 24 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
33328964
Default Alt Text
D57072.id178040.diff (3 KB)

Event Timeline