diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2005-09-26 23:02:14 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2005-09-26 23:02:14 +0000 |
commit | 2f897e72580eb68526972caf3ef815c5be50daba (patch) | |
tree | 1060decdf2fdb4e20562c150a787a9a763d47abc /src | |
parent | 80065b498ba12f0cc5326e08c2650104ae1d3081 (diff) | |
download | coreutils-2f897e72580eb68526972caf3ef815c5be50daba.tar.xz |
(touch): Handle "touch -c - >&-" by checking for EBADF
and ENOSYS.
Do not pass "-" to futimens; pass NULL instead.
If close (STDIN_FILENO) fails, report the error separately instead
of letting the 'close' pollute errno.
Diffstat (limited to 'src')
-rw-r--r-- | src/touch.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/src/touch.c b/src/touch.c index 870606123..06c9646bc 100644 --- a/src/touch.c +++ b/src/touch.c @@ -154,7 +154,7 @@ touch (const char *file) error (0, open_errno, _("creating %s"), quote (file)); else { - if (no_create && errno == ENOENT) + if (no_create && (errno == ENOENT || errno == EBADF)) return true; error (0, errno, _("failed to get attributes of %s"), quote (file)); @@ -182,9 +182,23 @@ touch (const char *file) t = timespec; } - ok = (futimens (fd, file, t) == 0); + ok = (futimens (fd, (fd == STDOUT_FILENO ? NULL : file), t) == 0); + if (fd == STDIN_FILENO) - ok &= (close (fd) == 0); + { + if (close (STDIN_FILENO) != 0) + { + error (0, errno, _("closing %s"), quote (file)); + return false; + } + } + else if (fd == STDOUT_FILENO) + { + /* Do not diagnose "touch -c - >&-". */ + if (!ok && errno == EBADF && no_create + && change_times == (CH_ATIME | CH_MTIME)) + return true; + } if (!ok) { |