1
0

LESS THAN 250 LINES

This commit is contained in:
dtb 2024-01-19 21:49:40 -07:00
parent 88a9425ad7
commit cebb888918

22
mm/mm.c
View File

@ -21,7 +21,7 @@
#include <stdio.h> /* fclose(3), fopen(3), fprintf(3), getc(3), putc(3),
* setvbuf(3), size_t, _IONBF, NULL */
#include <stdlib.h> /* free(3), realloc(3) */
#include <string.h> /* strerror(3) */
#include <string.h> /* strcmp(3), strerror(3) */
#include <unistd.h> /* getopt(3) */
#if !defined EX_OSERR || !defined EX_USAGE
# include <sysexits.h>
@ -161,24 +161,18 @@ int main(int argc, char *argv[]){
terminate(files);
return oserr(argv[0], "-e");
case 'i':
if(optarg[0] == '-' && optarg[1] == '\0'){ /* "-" */
if(Files_append(&files[0], stdin, stdin_name)
if((strcmp(optarg, "-") == 0 && Files_append(&files[0],
stdin, stdin_name) != NULL)
|| Files_open(&files[0], optarg)
!= NULL)
break;
else
optarg = stdin_name;
}else if(Files_open(&files[0], optarg) != NULL)
break;
terminate(files);
return oserr(argv[0], optarg);
case 'o':
if(optarg[0] == '-' && optarg[1] == '\0'){
/* "-" */
if(Files_append(&files[1], stdout,
stdout_name) != NULL)
break;
optarg = stdout_name;
}else if(Files_open(&files[1], optarg) != NULL)
if((strcmp(optarg, "-") == 0 && Files_append(&files[1],
stdout, stdout_name) != NULL)
|| Files_open(&files[1], optarg)
!= NULL)
break;
/* does not exist, so try to create it */
if(errno == ENOENT){