]> git.ipfire.org Git - thirdparty/util-linux.git/blobdiff - misc-utils/namei.c
Merge branch '2018wk48' of https://github.com/kerolasa/util-linux
[thirdparty/util-linux.git] / misc-utils / namei.c
index 92ee22e1fbd0ed07372664866993da83a9d95baf..60171f60028225f3b616ad6145ba7f0884413254 100644 (file)
@@ -59,7 +59,7 @@ struct namei {
        struct namei    *next;          /* next item */
        int             level;
        int             mountpoint;     /* is mount point */
-       int             noent;          /* is this item not existing */
+       int             noent;          /* this item not existing (stores errno from stat()) */
 };
 
 static int flags;
@@ -151,9 +151,10 @@ new_namei(struct namei *parent, const char *path, const char *fname, int lev)
        nm->level = lev;
        nm->name = xstrdup(fname);
 
-       nm->noent = (lstat(path, &nm->st) == -1);
-       if (nm->noent)
+       if (lstat(path, &nm->st) != 0) {
+               nm->noent = errno;
                return nm;
+       }
 
        if (S_ISLNK(nm->st.st_mode))
                readlink_to_namei(nm, path);
@@ -280,7 +281,7 @@ print_namei(struct namei *nm, char *path)
                                blanks += 1;
                        blanks += nm->level * 2;
                        printf("%*s ", blanks, "");
-                       printf(_("%s - No such file or directory\n"), nm->name);
+                       printf("%s - %s\n", nm->name, strerror(nm->noent));
                        return -1;
                }
 
@@ -343,9 +344,9 @@ static void __attribute__((__noreturn__)) usage(void)
                " -l, --long          use a long listing format (-m -o -v) \n"
                " -n, --nosymlinks    don't follow symlinks\n"
                " -v, --vertical      vertical align of modes and owners\n"), out);
-       print_usage_help_options(21);
+       printf(USAGE_HELP_OPTIONS(21));
 
-       fprintf(out, USAGE_MAN_TAIL("namei(1)"));
+       printf(USAGE_MAN_TAIL("namei(1)"));
        exit(EXIT_SUCCESS);
 }