From 7088e9294eb9303d8d90f39bf7178b08d4337fa2 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 15 Sep 2001 17:07:24 +0000 Subject: [PATCH] (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. --- src/touch.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/touch.c b/src/touch.c index 35fa58f..517ec84 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; } -- 2.7.4