diff --git a/cat/Makefile b/cat/Makefile new file mode 100644 index 0000000..22217fe --- /dev/null +++ b/cat/Makefile @@ -0,0 +1,7 @@ +cat: cat.c + $(CC) -g -o cat cat.c + +clean: + rm -f cat.c + +.PHONY: clean diff --git a/cat/cat.c b/cat/cat.c index a80fa17..b1d7147 100644 --- a/cat/cat.c +++ b/cat/cat.c @@ -14,7 +14,7 @@ static char *default_argv[] = { "-", (char *)NULL }; -static char *stdout_name = "/dev/stdout"; +static char *stdout_name = "/dev/stdin"; int main(int argc, char *argv[]){ int arguing; @@ -54,8 +54,8 @@ int main(int argc, char *argv[]){ continue; } if(*argv[optind] == '-' && argv[optind][1] == '\0'){ /* "-" */ - fn = stdout_name; - fo = stdout; + fn = stdin_name; + fo = stdin; }else{ fn = argv[optind]; if(stat(fn, &fi) == -1){ @@ -103,7 +103,8 @@ int main(int argc, char *argv[]){ return EX_UNAVAILABLE; } - fclose(fo); + if(fo != stdin) + fclose(fo); ++optind; }