]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
Use one fewer file descriptor in a common case.
authorJim Meyering <jim@meyering.net>
Sun, 14 Aug 2005 14:18:07 +0000 (14:18 +0000)
committerJim Meyering <jim@meyering.net>
Sun, 14 Aug 2005 14:18:07 +0000 (14:18 +0000)
Include "fd-reopen.h", rather than "fcntl--.h".
Use fd_reopen rather than open.

src/touch.c

index e7008c18ab760d585098b7f31eb537d3cb1b78de..c7d5c009c0d63f2160ba51544fccb85f5fd297f7 100644 (file)
@@ -26,7 +26,7 @@
 #include "system.h"
 #include "argmatch.h"
 #include "error.h"
-#include "fcntl--.h"
+#include "fd-reopen.h"
 #include "getdate.h"
 #include "posixtm.h"
 #include "posixver.h"
@@ -127,8 +127,9 @@ touch (const char *file)
   if (! no_create)
     {
       /* 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);
+      fd = fd_reopen (STDIN_FILENO, file,
+                     O_WRONLY | O_CREAT | O_NONBLOCK | O_NOCTTY,
+                     S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
 
       /* 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