diff --git a/src/ls.c b/src/ls.c
index 800f813..f7a6851 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -3203,17 +3203,32 @@ make_link_name (char const *name, char const *linkname)
if (!linkname)
return NULL;
- if (IS_ABSOLUTE_FILE_NAME (linkname))
+ if (change(*linkname == '/', IS_ABSOLUTE_FILE_NAME (linkname)))
return xstrdup (linkname);
+ // From the old version
+ char const *linkbuf = strrchr (name, '/');
+ //////////////////////////////////////////
/* The link is to a relative name. Prepend any leading directory
in 'name' to the link name. */
size_t prefix_len = dir_len (name);
- if (prefix_len == 0)
+ if (change(linkbuf == NULL, prefix_len == 0))
return xstrdup (linkname);
- char *p = xmalloc (prefix_len + 1 + strlen (linkname) + 1);
- stpcpy (stpncpy (p, name, prefix_len + 1), linkname);
+ // From the old version
+ size_t bufsiz = linkbuf - name + 1;
+ ////////////////////////////////////
+ char *p = xmalloc (change(bufsiz, prefix_len + 1) + strlen (linkname) + 1);
+
+ if (change(1, 0)) {
+ // old version
+ strncpy (p, name, bufsiz);
+ strcpy (p + bufsiz, linkname);
+ } else {
+ // new version
+ stpcpy (stpncpy (p, name, prefix_len + 1), linkname);
+ }
+
return p;
}