From d1dca71078a9ed8eef35ba2b790d1e7db9421f66 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Wed, 7 Oct 2009 01:34:36 +0200 Subject: [PATCH] namei: fix alone symlink evaluation $ mkdir aaa $ ln -s aaa mylink old version: $ namei mylink namei: could not stat 'mylink/aaa': No such file or directory new version: $ namei mylink f: mylink l mylink -> aaa d aaa Signed-off-by: Karel Zak --- misc-utils/namei.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/misc-utils/namei.c b/misc-utils/namei.c index b8930cdf..ebd82fdb 100644 --- a/misc-utils/namei.c +++ b/misc-utils/namei.c @@ -190,14 +190,15 @@ readlink_to_namei(struct namei *nm, const char *path) if (*sym != '/') { char *p = strrchr(path, '/'); - nm->relstart = p ? p - path : strlen(path); - sz += nm->relstart + 1; + nm->relstart = p ? p - path : 0; + if (nm->relstart) + sz += nm->relstart + 1; } nm->abslink = malloc(sz + 1); if (!nm->abslink) err(EXIT_FAILURE, _("out of memory?")); - if (*sym != '/') { + if (*sym != '/' && nm->relstart) { /* create the absolute path from the relative symlink */ memcpy(nm->abslink, path, nm->relstart); *(nm->abslink + nm->relstart) = '/'; -- 2.39.5