summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2012-04-18 13:36:11 +0200
committerJim Meyering <meyering@redhat.com>2012-04-19 13:10:36 +0200
commit280aa28c4dc82f394d423bfceaac29b5b48c3cd2 (patch)
treeb48f06663e998a18a49b2235faf8e05ba574d107 /src
parente50751d8458888ba639e80460b1a6a7ce33efe3a (diff)
downloadcoreutils-280aa28c4dc82f394d423bfceaac29b5b48c3cd2.tar.xz
maint: modernize/clean-up a small function in ls.c
* src/ls.c (make_link_name): Adjust comment style to refer to VARIABLE names, not 'variable'. Move each of two declarations "down" to first use. Compare pointer to NULL, not to 0. Don't reuse local, "linkbuf" for a different purpose.
Diffstat (limited to 'src')
-rw-r--r--src/ls.c25
1 files changed, 11 insertions, 14 deletions
diff --git a/src/ls.c b/src/ls.c
index f1dfb1e4e..db5819280 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -3193,17 +3193,14 @@ get_link_name (char const *filename, struct fileinfo *f, bool command_line_arg)
filename);
}
-/* If 'linkname' is a relative name and 'name' contains one or more
- leading directories, return 'linkname' with those directories
- prepended; otherwise, return a copy of 'linkname'.
- If 'linkname' is zero, return zero. */
+/* If LINKNAME is a relative name and NAME contains one or more
+ leading directories, return LINKNAME with those directories
+ prepended; otherwise, return a copy of LINKNAME.
+ If LINKNAME is NULL, return NULL. */
static char *
make_link_name (char const *name, char const *linkname)
{
- char *linkbuf;
- size_t bufsiz;
-
if (!linkname)
return NULL;
@@ -3212,15 +3209,15 @@ make_link_name (char const *name, char const *linkname)
/* The link is to a relative name. Prepend any leading directory
in 'name' to the link name. */
- linkbuf = strrchr (name, '/');
- if (linkbuf == 0)
+ char const *linkbuf = strrchr (name, '/');
+ if (linkbuf == NULL)
return xstrdup (linkname);
- bufsiz = linkbuf - name + 1;
- linkbuf = xmalloc (bufsiz + strlen (linkname) + 1);
- strncpy (linkbuf, name, bufsiz);
- strcpy (linkbuf + bufsiz, linkname);
- return linkbuf;
+ size_t bufsiz = linkbuf - name + 1;
+ char *p = xmalloc (bufsiz + strlen (linkname) + 1);
+ strncpy (p, name, bufsiz);
+ strcpy (p + bufsiz, linkname);
+ return p;
}
/* Return true if the last component of NAME is '.' or '..'