cat(1p): print errors to stderr

This commit is contained in:
Emma Tebibyte 2023-08-14 00:17:09 -06:00
parent dd584b2886
commit 96d692d26e
Signed by untrusted user: emma
GPG Key ID: 6D661C738815E7DD

View File

@ -72,7 +72,7 @@ int main(int argc, char *argv[]) {
u = true;
break;
default:
printf("Usage: %s (-u) file...\n", argv[0]);
fprintf(stderr, "Usage: %s (-u) file...\n", argv[0]);
return EX_USAGE;
}
}
@ -102,22 +102,22 @@ int main(int argc, char *argv[]) {
} else if ((file = fopen(argv[i], "r")) == NULL) {
switch (errno) {
case EACCES:
printf("%s: %s: Permission denied.\n", argv[0], argv[i]);
fprintf(stderr, "%s: %s: Permission denied.\n", argv[0], argv[i]);
return EX_NOINPUT;
case EISDIR:
printf("%s: %s: Is a directory.\n", argv[0], argv[i]);
fprintf(stderr, "%s: %s: Is a directory.\n", argv[0], argv[i]);
return EX_NOINPUT;
case ELOOP:
printf("%s: %s: Is a symbolic link loop.\n", argv[0], argv[i]);
fprintf(stderr, "%s: %s: Is a symbolic link loop.\n", argv[0], argv[i]);
return EX_UNAVAILABLE;
case EMFILE:
printf("%s: Internal error.\n", argv[0]);
fprintf(stderr, "%s: Internal error.\n", argv[0]);
return EX_SOFTWARE;
case ENOENT: case ENOTDIR: case ENXIO:
printf("%s: %s: No such file or directory.\n", argv[0], argv[i]);
fprintf(stderr, "%s: %s: No such file or directory.\n", argv[0], argv[i]);
return EX_NOINPUT;
default:
printf("%s: Unknown error.\n", argv[0]);
fprintf(stderr, "%s: Unknown error.\n", argv[0]);
return EX_UNAVAILABLE;
}
}