Support reading from stdin using "-f -"

This commit is contained in:
Joseph C. Lehner 2016-02-11 22:25:35 +01:00
parent c21921c5ce
commit 936219b598
2 changed files with 10 additions and 6 deletions

2
nmrp.c
View file

@ -290,7 +290,7 @@ int nmrp_do(struct nmrpd_args *args)
return 1;
}
if (access(args->filename, R_OK) == -1) {
if (strcmp(args->filename, "-") && access(args->filename, R_OK) == -1) {
fprintf(stderr, "Error accessing file '%s'.\n", args->filename);
return 1;
}

14
tftp.c
View file

@ -232,11 +232,15 @@ int tftp_put(struct nmrpd_args *args)
sock = -1;
ret = -1;
fd = open(args->filename, O_RDONLY);
if (fd < 0) {
perror("open");
ret = fd;
goto cleanup;
if (!strcmp(args->filename, "-")) {
fd = STDIN_FILENO;
} else {
fd = open(args->filename, O_RDONLY);
if (fd < 0) {
perror("open");
ret = fd;
goto cleanup;
}
}
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);