commit: 7a5c0cd5fa00811705116de2d8f4fbf026bbe589
parent 72667749cf505fb425d17338ab550059ae47f957
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 20 Sep 2024 04:43:21 +0200
cmd/touch: unify error message formatting
Diffstat:
1 file changed, 22 insertions(+), 10 deletions(-)
diff --git a/cmd/touch.c b/cmd/touch.c
@@ -151,7 +151,7 @@ main(int argc, char *argv[])
target = opt_t_parse(optarg, &errstr);
if(errstr != NULL)
{
- fprintf(stderr, "touch: opt_t_parse(\"%s\", …): %s\n", optarg, errstr);
+ fprintf(stderr, "touch: error: opt_t_parse(\"%s\", …): %s\n", optarg, errstr);
exit(EXIT_FAILURE);
}
break;
@@ -172,12 +172,12 @@ main(int argc, char *argv[])
char *s = iso_parse(optarg, &iso_res, &nsec, &errstr);
if(errstr != NULL)
{
- fprintf(stderr, "touch: iso_parse(\"%s\", …): %s\n", optarg, errstr);
+ fprintf(stderr, "touch: error: iso_parse(\"%s\", …): %s\n", optarg, errstr);
exit(EXIT_FAILURE);
}
if(s == NULL)
{
- fprintf(stderr, "touch: iso_parse(\"%s\", …) returned NULL\n", optarg);
+ fprintf(stderr, "touch: error: iso_parse(\"%s\", …) returned NULL\n", optarg);
exit(EXIT_FAILURE);
}
@@ -185,17 +185,17 @@ main(int argc, char *argv[])
target.tv_nsec = nsec;
if(target.tv_sec == (time_t)-1)
{
- fprintf(stderr, "date: mktime: %s\n", strerror(errno));
+ fprintf(stderr, "touch: error: mktime: %s\n", strerror(errno));
exit(EXIT_FAILURE);
}
errno = 0;
break;
}
case ':':
- fprintf(stderr, "touch: Error: Missing operand for option: '-%c'\n", optopt);
+ fprintf(stderr, "touch: error: Missing operand for option: '-%c'\n", optopt);
return 1;
case '?':
- fprintf(stderr, "touch: Error: Unrecognised option: '-%c'\n", optopt);
+ fprintf(stderr, "touch: error: Unrecognised option: '-%c'\n", optopt);
return 1;
}
}
@@ -221,7 +221,10 @@ main(int argc, char *argv[])
if(stat(ref_file, &ref) != 0)
{
- fprintf(stderr, "touch: error: Failed getting status of file '%s': %s\n", ref_file, strerror(errno));
+ fprintf(stderr,
+ "touch: error: Failed getting status of file '%s': %s\n",
+ ref_file,
+ strerror(errno));
return 1;
}
@@ -246,7 +249,10 @@ main(int argc, char *argv[])
{
if(utimensat(AT_FDCWD, file, times, utimensat_flags) != 0)
{
- fprintf(stderr, "touch: error: Failed setting new times on directory '%s': %s\n", file, strerror(errno));
+ fprintf(stderr,
+ "touch: error: Failed setting new times on directory '%s': %s\n",
+ file,
+ strerror(errno));
return 1;
}
@@ -261,13 +267,19 @@ main(int argc, char *argv[])
if(futimens(fd, times) != 0)
{
- fprintf(stderr, "touch: error: Failed setting new times on file '%s': %s\n", file, strerror(errno));
+ fprintf(stderr,
+ "touch: error: Failed setting new times on file '%s': %s\n",
+ file,
+ strerror(errno));
return 1;
}
if(close(fd) != 0)
{
- fprintf(stderr, "touch: error: Failed closing file-descriptor for file '%s': %s\n", file, strerror(errno));
+ fprintf(stderr,
+ "touch: error: Failed closing file-descriptor for file '%s': %s\n",
+ file,
+ strerror(errno));
return 1;
}
}