1
0
This commit is contained in:
dtb 2023-08-17 10:41:05 -04:00
parent f315bdf4ae
commit c21ca4a2ce
2 changed files with 12 additions and 4 deletions

7
cat/Makefile Normal file
View File

@ -0,0 +1,7 @@
cat: cat.c
$(CC) -g -o cat cat.c
clean:
rm -f cat.c
.PHONY: clean

View File

@ -14,7 +14,7 @@ static char *default_argv[] = {
"-", "-",
(char *)NULL (char *)NULL
}; };
static char *stdout_name = "/dev/stdout"; static char *stdout_name = "/dev/stdin";
int main(int argc, char *argv[]){ int main(int argc, char *argv[]){
int arguing; int arguing;
@ -54,8 +54,8 @@ int main(int argc, char *argv[]){
continue; continue;
} }
if(*argv[optind] == '-' && argv[optind][1] == '\0'){ /* "-" */ if(*argv[optind] == '-' && argv[optind][1] == '\0'){ /* "-" */
fn = stdout_name; fn = stdin_name;
fo = stdout; fo = stdin;
}else{ }else{
fn = argv[optind]; fn = argv[optind];
if(stat(fn, &fi) == -1){ if(stat(fn, &fi) == -1){
@ -103,7 +103,8 @@ int main(int argc, char *argv[]){
return EX_UNAVAILABLE; return EX_UNAVAILABLE;
} }
fclose(fo); if(fo != stdin)
fclose(fo);
++optind; ++optind;
} }