From e3513e18955dd7b8d236695040186ec438e7f55a Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 25 Sep 2005 06:12:21 +0000 Subject: (touch): "touch -" now touches standard output. (usage): Document this. --- src/touch.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src') 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); } -- cgit v1.2.3-70-g09d2