summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1999-05-06 02:10:34 +0000
committerJim Meyering <jim@meyering.net>1999-05-06 02:10:34 +0000
commita4407423303cfae0250513c78be2444521938854 (patch)
tree13403674e903daaf3e537ed0ff45a4eda43a10e1 /lib
parentf466b6448a2a4ee2060f2b3b52a1b9d4ac8ecf50 (diff)
downloadcoreutils-a4407423303cfae0250513c78be2444521938854.tar.xz
(make_dir): When reporting a mkdir failure and the
target cannot be `stat'ed, use the errno from the failed mkdir call, not the one from the stat call. Before this change, running `mkdir -p /no-dir/no-dir' as an unprivileged user would wrongly elicit `No such file or directory' instead of `Permission denied'.
Diffstat (limited to 'lib')
-rw-r--r--lib/makepath.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/lib/makepath.c b/lib/makepath.c
index 4a758e37a..20e9a1288 100644
--- a/lib/makepath.c
+++ b/lib/makepath.c
@@ -162,6 +162,7 @@ make_dir (const char *dir, const char *dirpath, mode_t mode, int *created_dir_p)
if (!created_dir)
{
struct stat stats;
+ int saved_errno = errno;
/* The mkdir and stat calls below may appear to be reversed.
They are not. It is important to call mkdir first and then to
@@ -173,7 +174,7 @@ make_dir (const char *dir, const char *dirpath, mode_t mode, int *created_dir_p)
if (stat (dir, &stats))
{
- error (0, errno, _("cannot create directory `%s'"), dirpath);
+ error (0, saved_errno, _("cannot create directory `%s'"), dirpath);
fail = 1;
}
else if (!S_ISDIR (stats.st_mode))