diff options
author | Paul Eggert <eggert@cs.ucla.edu> | 2005-09-25 06:12:21 +0000 |
---|---|---|
committer | Paul Eggert <eggert@cs.ucla.edu> | 2005-09-25 06:12:21 +0000 |
commit | e3513e18955dd7b8d236695040186ec438e7f55a (patch) | |
tree | 287fc34a314ced18f2985562f0fff285e435f5ff /src | |
parent | 17ccbf8844982f957bdf9adb981871fce698b4bb (diff) | |
download | coreutils-e3513e18955dd7b8d236695040186ec438e7f55a.tar.xz |
(touch): "touch -" now touches standard output.
(usage): Document this.
Diffstat (limited to 'src')
-rw-r--r-- | src/touch.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/touch.c b/src/touch.c index 1eaf8fa88..870606123 100644 --- a/src/touch.c +++ b/src/touch.c @@ -125,7 +125,9 @@ touch (const char *file) struct timespec timespec[2]; struct timespec const *t; - if (! no_create) + if (STREQ (file, "-")) + fd = STDOUT_FILENO; + else if (! no_create) { /* Try to open FILE, creating it if necessary. */ fd = fd_reopen (STDIN_FILENO, file, @@ -157,7 +159,7 @@ touch (const char *file) error (0, errno, _("failed to get attributes of %s"), quote (file)); } - if (fd != -1) + if (fd == STDIN_FILENO) close (fd); return false; } @@ -181,7 +183,7 @@ touch (const char *file) } ok = (futimens (fd, file, t) == 0); - if (fd != -1) + if (fd == STDIN_FILENO) ok &= (close (fd) == 0); if (!ok) @@ -241,6 +243,8 @@ Mandatory arguments to long options are mandatory for short options too.\n\ fputs (_("\ \n\ Note that the -d and -t options accept different time-date formats.\n\ +\n\ +If a FILE is -, touch standard output.\n\ "), stdout); printf (_("\nReport bugs to <%s>.\n"), PACKAGE_BUGREPORT); } |