diff options
author | Michal Luscon | 2012-02-08 16:01:51 +0100 |
---|---|---|
committer | Karel Zak | 2012-03-27 13:04:58 +0200 |
commit | 6d45c65d076ef9c5fc7295c9dcc9051519eb21f9 (patch) | |
tree | 23ae399840b617f0b469570ce3361f8a9e043e75 /misc-utils/eject.c | |
parent | eject: replace fprintf with err and warn (diff) | |
download | kernel-qcow2-util-linux-6d45c65d076ef9c5fc7295c9dcc9051519eb21f9.tar.gz kernel-qcow2-util-linux-6d45c65d076ef9c5fc7295c9dcc9051519eb21f9.tar.xz kernel-qcow2-util-linux-6d45c65d076ef9c5fc7295c9dcc9051519eb21f9.zip |
eject: use canonicalize_path to treat symbolic links
Signed-off-by: Michal Luscon <mluscon@redhat.com>
Diffstat (limited to 'misc-utils/eject.c')
-rw-r--r-- | misc-utils/eject.c | 40 |
1 files changed, 2 insertions, 38 deletions
diff --git a/misc-utils/eject.c b/misc-utils/eject.c index c685c4286..974e566aa 100644 --- a/misc-utils/eject.c +++ b/misc-utils/eject.c @@ -34,6 +34,7 @@ #include "nls.h" #include "strutils.h" #include "xalloc.h" +#include "canonicalize.h" #define EJECT_DEFAULT_DEVICE "/dev/cdrom" @@ -759,43 +760,6 @@ static void UnmountDevices(const char *pattern) e_fclose(fp); } - -/* Check if name is a symbolic link. If so, return what it points to. */ -static char *SymLink(const char *name) -{ - int status; - char s1[PATH_MAX]; - char s2[PATH_MAX]; - char s4[PATH_MAX]; - char result[PATH_MAX]; - char *s3; - - memset(s1, 0, sizeof(s1)); - memset(s2, 0, sizeof(s2)); - memset(s4, 0, sizeof(s4)); - memset(result, 0, sizeof(result)); - - status = readlink(name, s1, sizeof(s1) - 1); - - if (status == -1) - return 0; - - s1[status] = 0; - if (s1[0] == '/') { /* absolute link */ - return strdup(s1); - } else { /* relative link, add base name */ - strncpy(s2, name, sizeof(s2)-1); - s3 = strrchr(s2, '/'); - if (s3 != 0) { - s3[1] = 0; - snprintf(result, sizeof(result)-1, "%s%s", s2, s1); - } - } - realpath(result, s4); - return strdup(s4); -} - - /* * Given a name, see if it matches a pattern for a device that can have * multiple partitions. If so, return a regular expression that matches @@ -910,7 +874,7 @@ int main(int argc, char **argv) printf(_("%s: expanded name is `%s'\n"), programName, fullName); /* check for a symbolic link */ - while ((linkName = SymLink(fullName)) && (ld > 0)) { + while ((linkName = canonicalize_path(fullName)) && (ld > 0)) { if (v_option) printf(_("%s: `%s' is a link to `%s'\n"), programName, fullName, linkName); free(fullName); |