commit: 686474c85a4bd6ad53d56eaa82cef11358edd898
parent 21898bfb0b7de4301ef2290d4299fe864c46fccc
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date: Fri, 20 Sep 2024 02:55:51 +0200
cmd/ln: unify error message formatting
Diffstat:
2 files changed, 19 insertions(+), 17 deletions(-)
diff --git a/cmd/ln.c b/cmd/ln.c
@@ -35,7 +35,7 @@ do_link(char *src, char *dest)
if(errno != EEXIST)
{
- fprintf(stderr, "ln: Failed creating symlink '%s': %s\n", dest, strerror(errno));
+ fprintf(stderr, "ln: error: Failed creating symlink '%s': %s\n", dest, strerror(errno));
return -1;
}
}
@@ -46,7 +46,7 @@ do_link(char *src, char *dest)
if(errno != EEXIST)
{
fprintf(stderr,
- "ln: Failed creating hard link from '%s' to '%s': %s\n",
+ "ln: error: Failed creating hard link from '%s' to '%s': %s\n",
src,
dest,
strerror(errno));
@@ -70,7 +70,7 @@ do_link(char *src, char *dest)
{
if(!force)
{
- fprintf(stderr, "ln: Error: Destination '%s' already exists\n", dest);
+ fprintf(stderr, "ln: error: Destination '%s' already exists\n", dest);
return -1;
}
@@ -81,7 +81,7 @@ do_link(char *src, char *dest)
if(unlink(dest) < 0)
{
fprintf(stderr,
- "ln: Failed removing already existing destination '%s': %s\n",
+ "ln: error: Failed removing already existing destination '%s': %s\n",
dest,
strerror(errno));
return -1;
@@ -91,8 +91,10 @@ do_link(char *src, char *dest)
if(errno != 0)
{
- fprintf(
- stderr, "ln: Failed opening destination as directory '%s': %s\n", dest, strerror(errno));
+ fprintf(stderr,
+ "ln: error: Failed opening destination as directory '%s': %s\n",
+ dest,
+ strerror(errno));
return -1;
}
@@ -100,7 +102,7 @@ do_link(char *src, char *dest)
{
if(symlinkat(src, dirfd, dest) == 0) goto cleanup;
- fprintf(stderr, "ln: Failed creating symlink '%s': %s\n", dest, strerror(errno));
+ fprintf(stderr, "ln: error: Failed creating symlink '%s': %s\n", dest, strerror(errno));
return -1;
}
else
@@ -108,7 +110,7 @@ do_link(char *src, char *dest)
if(linkat(AT_FDCWD, src, dirfd, dest, link_flags) == 0) goto cleanup;
fprintf(stderr,
- "ln: Failed creating hard link from '%s' to '%s': %s\n",
+ "ln: error: Failed creating hard link from '%s' to '%s': %s\n",
src,
dest,
strerror(errno));
@@ -120,7 +122,7 @@ cleanup:
if(close(dirfd) != 0)
{
- fprintf(stderr, "ln: Failed closing directory '%s': %s\n", dest, strerror(errno));
+ fprintf(stderr, "ln: error: Failed closing directory '%s': %s\n", dest, strerror(errno));
return -1;
}
@@ -160,7 +162,7 @@ main(int argc, char *argv[])
FIELD_CLR(link_flags, AT_SYMLINK_FOLLOW);
break;
case '?':
- fprintf(stderr, "ln: Unknown option '-%c'\n", optopt);
+ fprintf(stderr, "ln: error: Unknown option '-%c'\n", optopt);
usage();
break;
}
@@ -173,7 +175,7 @@ main(int argc, char *argv[])
if(argc <= 1)
{
- fprintf(stderr, "ln: Not enough operands, %d given, expect >= 2\n", argc);
+ fprintf(stderr, "ln: error: Not enough operands, %d given, expect >= 2\n", argc);
return 1;
}
else if(argc == 2)
@@ -202,7 +204,7 @@ main(int argc, char *argv[])
if(snprintf(target, PATH_MAX, "%s/%s", dest, src_basename) < 0)
{
- fprintf(stderr, "ln: Failed joining destination '%s' and target '%s'\n", dest, src);
+ fprintf(stderr, "ln: error: Failed joining destination '%s' and target '%s'\n", dest, src);
return 1;
}
diff --git a/test-cmd/ln.t b/test-cmd/ln.t
@@ -7,11 +7,11 @@
$ test "$(command -v ln)" = "$TESTDIR/../cmd/ln"
$ ln hard_enoent_src hard_enoent_dest
- ln: Failed creating hard link from 'hard_enoent_src' to 'hard_enoent_dest': No such file or directory
+ ln: error: Failed creating hard link from 'hard_enoent_src' to 'hard_enoent_dest': No such file or directory
[1]
$ ln -s hard_enoent_ref1 hard_enoent_ref2 hard_enoent_dest
- ln: Failed creating symlink 'hard_enoent_dest/hard_enoent_ref1': No such file or directory
+ ln: error: Failed creating symlink 'hard_enoent_dest/hard_enoent_ref1': No such file or directory
[1]
$ touch hard_file_src
@@ -33,7 +33,7 @@
$ rm sym_enoent_dest
$ ln -s sym_enoent_ref1 sym_enoent_ref2 sym_enoent_dest
- ln: Failed creating symlink 'sym_enoent_dest/sym_enoent_ref1': No such file or directory
+ ln: error: Failed creating symlink 'sym_enoent_dest/sym_enoent_ref1': No such file or directory
[1]
$ mkdir sym_dir_slash
@@ -54,7 +54,7 @@
$ touch force_symlink
$ ln -s foo force_symlink
- ln: Error: Destination 'force_symlink' already exists
+ ln: error: Destination 'force_symlink' already exists
[1]
$ test -L force_symlink
[1]
@@ -65,7 +65,7 @@
$ mkdir n_directory
$ ln -s n_directory n_dir_symlink
$ ln -sn //example.org n_dir_symlink
- ln: Error: Destination 'n_dir_symlink' already exists
+ ln: error: Destination 'n_dir_symlink' already exists
[1]
$ readlink n_dir_symlink
n_directory