dj(1): interpret a '-' file name as standard input/output

This commit is contained in:
dtb 2024-01-10 15:03:04 -07:00
parent 88a66bcc01
commit 612067890f
Signed by: trinity
GPG Key ID: 31FF85CCB6DC7641

View File

@ -314,7 +314,12 @@ int main(int argc, char *argv[]){
while((c = getopt(argc, argv, "a:Ab:B:c:di:fhHqs:S:o:")) != -1) while((c = getopt(argc, argv, "a:Ab:B:c:di:fhHqs:S:o:")) != -1)
switch(c){ switch(c){
case 'i': case 'o': case 'i': case 'o':
if(Io_fdopen(&ep[c == 'o'], optarg) != -1) i = (c == 'o');
if(optarg[0] == '-' && optarg[1] == '\0'){ /* optarg == "-" */
ep[i].fd = (i == 0) ? STDIN_FILENO : STDOUT_FILENO;
ep[i].fn = (i == 0) ? stdin_name : stdout_name;
break;
}else if(Io_fdopen(&ep[i], optarg) != -1)
break; break;
terminate(ep); terminate(ep);
return oserr(optarg); return oserr(optarg);