[hackers] [sbase] touch: Respect caller's umask || Michael Forney

From: <git_AT_suckless.org>
Date: Sat, 9 Jul 2016 11:17:21 +0200 (CEST)

commit 0941c9ab2c47447755b0d2267bd76ae3f5b9318a
Author: Michael Forney <mforney_AT_mforney.org>
AuthorDate: Fri Jul 8 10:24:11 2016 -0700
Commit: sin <sin_AT_2f30.org>
CommitDate: Sat Jul 9 10:17:16 2016 +0100

    touch: Respect caller's umask
    
    Currently, if the caller has a umask of 002 or 000, the file gets created as 644
    anyway.
    
    Also, add O_WRONLY to the open call, since POSIX says that "Applications shall
    specify exactly one of the first five values (file access modes) below in the
    value of oflag".

diff --git a/touch.c b/touch.c
index fca2f16..74bdc27 100644
--- a/touch.c
+++ b/touch.c
_AT_@ -38,7 +38,7 @@ touch(const char *file)
                 return;
         }
 
- if ((fd = open(file, O_CREAT | O_EXCL, 0644)) < 0)
+ if ((fd = open(file, O_WRONLY | O_CREAT | O_EXCL, 0666)) < 0)
                 eprintf("open %s:", file);
         close(fd);
 
Received on Sat Jul 09 2016 - 11:17:21 CEST

This archive was generated by hypermail 2.3.0 : Sat Jul 09 2016 - 11:24:30 CEST