]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
maint: ln: eliminate a clang -Wformat-extra-args warning
authorBruno Haible <bruno@clisp.org>
Thu, 18 Sep 2025 21:19:01 +0000 (23:19 +0200)
committerPádraig Brady <P@draigBrady.com>
Sat, 1 Nov 2025 14:15:24 +0000 (14:15 +0000)
* src/ln.c (do_link): Don't pass unused arguments to error().
Don't use "%.0s" to consume a string argument without printing it.

src/ln.c

index 3a40244fb7cecf0d57ad02ba477810763a36aad3..7a366bc907e7c86ac3858f1d411ffaec3d4555b2 100644 (file)
--- a/src/ln.c
+++ b/src/ln.c
@@ -369,18 +369,31 @@ do_link (char const *source, int destdir_fd, char const *dest_base,
     }
   else
     {
-      error (0, link_errno,
-             (symbolic_link
-              ? (link_errno != ENAMETOOLONG && *source
-                 ? _("failed to create symbolic link %s")
-                 : _("failed to create symbolic link %s -> %s"))
-              : (link_errno == EMLINK
-                 ? _("failed to create hard link to %.0s%s")
-                 : (link_errno == EDQUOT || link_errno == EEXIST
-                    || link_errno == ENOSPC || link_errno == EROFS)
-                 ? _("failed to create hard link %s")
-                 : _("failed to create hard link %s => %s"))),
-             quoteaf_n (0, dest), quoteaf_n (1, source));
+      char *dest_quoted = quoteaf_n (0, dest);
+      char *source_quoted = quoteaf_n (1, source);
+
+      if (symbolic_link)
+        {
+          if (link_errno != ENAMETOOLONG && *source)
+            error (0, link_errno, _("failed to create symbolic link %s"),
+                   dest_quoted);
+          else
+            error (0, link_errno, _("failed to create symbolic link %s -> %s"),
+                   dest_quoted, source_quoted);
+        }
+      else
+        {
+          if (link_errno == EMLINK)
+            error (0, link_errno, _("failed to create hard link to %s"),
+                   source_quoted);
+          else if (link_errno == EDQUOT || link_errno == EEXIST
+                   || link_errno == ENOSPC || link_errno == EROFS)
+            error (0, link_errno, _("failed to create hard link %s"),
+                   dest_quoted);
+          else
+            error (0, link_errno, _("failed to create hard link %s => %s"),
+                   dest_quoted, source_quoted);
+        }
 
       if (backup_base)
         {