summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2001-09-15 17:07:24 +0000
committerJim Meyering <jim@meyering.net>2001-09-15 17:07:24 +0000
commit7088e9294eb9303d8d90f39bf7178b08d4337fa2 (patch)
tree54d8de0f89aea4509d0d2c61fdb83d4162dca329 /src
parente1e9b12eadd800fb4da12d02288f6d6aaaab47b3 (diff)
downloadcoreutils-7088e9294eb9303d8d90f39bf7178b08d4337fa2.tar.xz
(EISDIR): Define to 0, if not already defined.
(touch): Give a better diagnostic for e.g., `touch /' by non-root. Based on a patch from Michael Stone. Reported by Jeff Sheinberg as Debian bug #101677.
Diffstat (limited to 'src')
-rw-r--r--src/touch.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/touch.c b/src/touch.c
index 35fa58f4d..517ec8481 100644
--- a/src/touch.c
+++ b/src/touch.c
@@ -57,6 +57,10 @@ time_t time ();
# define O_NOCTTY 0
#endif
+#if !defined EISDIR
+# define EISDIR 0
+#endif
+
/* The name by which this program was run. */
char *program_name;
@@ -138,7 +142,11 @@ touch (const char *file)
/* Try to open FILE, creating it if necessary. */
fd = open (file, O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY,
S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
- if (fd == -1)
+
+ /* Don't save a copy of errno if it's EISDIR, since that would lead
+ touch to give a bogus diagnostic for e.g., `touch /' (assuming
+ we don't own / or have write access to it). */
+ if (fd == -1 && errno != EISDIR)
open_errno = errno;
}