commit: 090b88be1892ca08ade620a7bd0c8ba4f5ac427b
parent 0e6c90b249b0f5d37f67d20cbc8d20d026280f4b
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 20 Sep 2024 04:22:00 +0200
cmd/tee: unify error message formatting
Diffstat:
3 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/cmd/sync.c b/cmd/sync.c
@@ -34,13 +34,14 @@ main(int argc, char *argv[])
break;
#else
fprintf(stderr,
- "sync: System doesn't supports syncfs(3), continuing with error status set\n");
+ "sync: error: System doesn't supports syncfs(3), continuing with error status set\n");
err = 1;
break;
#endif
case '?':
- fprintf(
- stderr, "sync: Unrecognized option '-%c', continuing with error status set\n", optopt);
+ fprintf(stderr,
+ "sync: error: Unrecognized option '-%c', continuing with error status set\n",
+ optopt);
err = 1;
break;
default:
@@ -54,7 +55,7 @@ main(int argc, char *argv[])
if(argc == 0)
{
#ifdef HAS_SYNCFS
- if(sync_func == syncfs) fprintf(stderr, "sync: Warning -f passed without arguments\n");
+ if(sync_func == syncfs) fprintf(stderr, "sync: warning: Option -f passed without arguments\n");
#endif
sync();
@@ -66,14 +67,14 @@ main(int argc, char *argv[])
int fd = open(argv[i], O_RDONLY);
if(fd < 0)
{
- fprintf(stderr, "sync: Failed opening file '%s': %s\n", argv[i], strerror(errno));
+ fprintf(stderr, "sync: error: Failed opening file '%s': %s\n", argv[i], strerror(errno));
return 1;
}
if(sync_func(fd) < 0)
{
fprintf(stderr,
- "sync: Failed synchronizing changes related to file '%s': %s\n",
+ "sync: error: Failed synchronizing changes related to file '%s': %s\n",
argv[i],
strerror(errno));
return 1;
@@ -82,7 +83,7 @@ main(int argc, char *argv[])
if(close(fd) < 0)
{
fprintf(stderr,
- "sync: Failed closing file-descriptor of file '%s': %s\n",
+ "sync: error: Failed closing file-descriptor of file '%s': %s\n",
argv[i],
strerror(errno));
return 1;
diff --git a/cmd/tee.c b/cmd/tee.c
@@ -38,10 +38,10 @@ main(int argc, char *argv[])
signal(SIGINT, SIG_IGN);
break;
case ':':
- fprintf(stderr, "tee: Error: Missing operand for option: '-%c'\n", optopt);
+ fprintf(stderr, "tee: error: Missing operand for option: '-%c'\n", optopt);
return 1;
case '?':
- fprintf(stderr, "tee: Error: Unrecognised option: '-%c'\n", optopt);
+ fprintf(stderr, "tee: error: Unrecognised option: '-%c'\n", optopt);
return 1;
default:
abort();
@@ -56,7 +56,7 @@ main(int argc, char *argv[])
fds = calloc(argc, sizeof(*fds));
if(!fds)
{
- fprintf(stderr, "tee: Cannot allocate fd array: %s\n", strerror(errno));
+ fprintf(stderr, "tee: error: Failed to allocate fd array: %s\n", strerror(errno));
return 1;
}
}
@@ -70,7 +70,7 @@ main(int argc, char *argv[])
if(fds[argi] == NULL)
{
- fprintf(stderr, "tee: Error opening ‘%s’: %s\n", argv[argi], strerror(errno));
+ fprintf(stderr, "tee: error: Failed opening file ‘%s’: %s\n", argv[argi], strerror(errno));
cleanup(fds);
return 1;
}
@@ -83,7 +83,7 @@ main(int argc, char *argv[])
{
if(fputc(c, stdout) == EOF)
{
- fprintf(stderr, "tee: Error writing ‘<stdout>’: %s\n", strerror(errno));
+ fprintf(stderr, "tee: error: Failed writing to stdout: %s\n", strerror(errno));
err = 1;
errno = 0;
}
@@ -92,7 +92,7 @@ main(int argc, char *argv[])
{
if(fputc(c, fds[argi]) == EOF)
{
- fprintf(stderr, "tee: Error writing to argument %d: %s\n", argi, strerror(errno));
+ fprintf(stderr, "tee: error: Failed writing to argument %d: %s\n", argi, strerror(errno));
err = 1;
errno = 0;
}
@@ -104,7 +104,7 @@ main(int argc, char *argv[])
{
if(fclose(fds[argi]) != 0)
{
- fprintf(stderr, "tee: I/O error when closing file '%s': %s\n", argv[argi], strerror(errno));
+ fprintf(stderr, "tee: error: Failed closing file '%s': %s\n", argv[argi], strerror(errno));
err++;
}
}
diff --git a/test-cmd/tee.sh b/test-cmd/tee.sh
@@ -23,20 +23,20 @@ t_cmd appendfile:rm '' rm "${tmp_appendfile}"
tmp_noperm="$(mktemp)"
t_cmd noperm:chmod_0000 '' chmod 0000 "${tmp_noperm}"
-t --exit=1 noperm "${tmp_noperm}" "tee: Error opening ‘${tmp_noperm}’: Permission denied
+t --exit=1 noperm "${tmp_noperm}" "tee: error: Failed opening file ‘${tmp_noperm}’: Permission denied
" </dev/null
t_cmd noperm:chmod_0600 '' chmod 0600 "${tmp_noperm}"
t_cmd noperm:rm '' rm "${tmp_noperm}"
t --input='' nullinput
-t --exit=1 --input='foo' writeslash './' 'tee: Error opening ‘./’: Is a directory
+t --exit=1 --input='foo' writeslash './' 'tee: error: Failed opening file ‘./’: Is a directory
'
-t --exit=1 --input='foo' enoent '/var/empty/e/no/ent' 'tee: Error opening ‘/var/empty/e/no/ent’: No such file or directory
+t --exit=1 --input='foo' enoent '/var/empty/e/no/ent' 'tee: error: Failed opening file ‘/var/empty/e/no/ent’: No such file or directory
'
t_file --infile="${WD}/inputs/all_bytes" doubledash "${WD}/inputs/all_bytes" --
-t --exit=1 --input='foo' tripledash '---' "tee: Error: Unrecognised option: '--'
+t --exit=1 --input='foo' tripledash '---' "tee: error: Unrecognised option: '--'
"