Changeset View
Standalone View
usr.bin/tftp/main.c
Show First 20 Lines • Show All 439 Lines • ▼ Show 20 Lines | |||||
/* | /* | ||||
* Send file(s). | * Send file(s). | ||||
*/ | */ | ||||
static void | static void | ||||
put(int argc, char *argv[]) | put(int argc, char *argv[]) | ||||
{ | { | ||||
int fd; | int fd; | ||||
int n; | int n; | ||||
char *cp, *targ; | char *cp, *targ, *path; | ||||
char line[MAXLINE]; | char line[MAXLINE]; | ||||
struct stat sb; | struct stat sb; | ||||
if (argc < 2) { | if (argc < 2) { | ||||
strcpy(line, "send "); | strcpy(line, "send "); | ||||
printf("(file) "); | printf("(file) "); | ||||
fgets(&line[strlen(line)], sizeof line - strlen(line), stdin); | fgets(&line[strlen(line)], sizeof line - strlen(line), stdin); | ||||
makeargv(line); | makeargv(line); | ||||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | if (verbose) | ||||
printf("putting %s to %s:%s [%s]\n", | printf("putting %s to %s:%s [%s]\n", | ||||
cp, hostname, targ, mode); | cp, hostname, targ, mode); | ||||
xmitfile(peer, port, fd, targ, mode); | xmitfile(peer, port, fd, targ, mode); | ||||
close(fd); | close(fd); | ||||
return; | return; | ||||
} | } | ||||
/* this assumes the target is a directory */ | /* this assumes the target is a directory */ | ||||
/* on a remote unix system. hmmmm. */ | /* on a remote unix system. hmmmm. */ | ||||
cp = strchr(targ, '\0'); | |||||
*cp++ = '/'; | |||||
for (n = 1; n < argc - 1; n++) { | for (n = 1; n < argc - 1; n++) { | ||||
strcpy(cp, tail(argv[n])); | if (asprintf(&path, "%s/%s", targ, tail(argv[n])) < 0) | ||||
err(1, "malloc"); | |||||
fd = open(argv[n], O_RDONLY); | fd = open(argv[n], O_RDONLY); | ||||
if (fd < 0) { | if (fd < 0) { | ||||
warn("%s", argv[n]); | warn("%s", argv[n]); | ||||
free(path); | |||||
continue; | continue; | ||||
imp: Do you need to free targ here? | |||||
} | } | ||||
if (fstat(fd, &sb) < 0) { | if (fstat(fd, &sb) < 0) { | ||||
warn("%s", argv[n]); | warn("%s", argv[n]); | ||||
close(fd); | |||||
Not Done Inline Actionsdo you need to free targ here? imp: do you need to free targ here? | |||||
free(path); | |||||
continue; | continue; | ||||
} | } | ||||
asprintf(&options[OPT_TSIZE].o_request, "%ju", sb.st_size); | asprintf(&options[OPT_TSIZE].o_request, "%ju", sb.st_size); | ||||
Not Done Inline ActionsI guess this presumably-leaky line is why you started looking at tsize? jrtc27: I guess this presumably-leaky line is why you started looking at tsize? | |||||
if (verbose) | if (verbose) | ||||
printf("putting %s to %s:%s [%s]\n", | printf("putting %s to %s:%s [%s]\n", | ||||
argv[n], hostname, targ, mode); | argv[n], hostname, path, mode); | ||||
xmitfile(peer, port, fd, targ, mode); | xmitfile(peer, port, fd, path, mode); | ||||
close(fd); | |||||
Not Done Inline ActionsAny reason for this blank line? jrtc27: Any reason for this blank line? | |||||
Done Inline ActionsSeemed right according to the prevailing style. If there is a blank line after the asprintf(), there should be one before the free(). des: Seemed right according to the prevailing style. If there is a blank line after the `asprintf()`… | |||||
Not Done Inline ActionsWhy's that relevant? There isn't one after every single function call in the file. The point of the blank line after the asprintf is to separate the configuration part of the block from the "go actually run it" part, and there isn't a blank line *before* it I would guess because it's tied to the preceding fstat. It's all a bit subjective, but I would argue this blank line here makes no sense, whereas the others are somewhat justifiable. If anything, put a blank line before the close here instead to separate cleanup from the rest of the code, but not in the middle of cleanup. jrtc27: Why's that relevant? There isn't one after every single function call in the file. The point of… | |||||
free(path); | |||||
} | } | ||||
} | } | ||||
static void | static void | ||||
putusage(char *s) | putusage(char *s) | ||||
{ | { | ||||
printf("usage: %s file [remotename]\n", s); | printf("usage: %s file [remotename]\n", s); | ||||
▲ Show 20 Lines • Show All 560 Lines • Show Last 20 Lines |
Do you need to free targ here?