[hackers] [PATCH 5/8] touch: Respect caller's umask

From: Michael Forney <mforney_AT_mforney.org>
Date: Fri, 8 Jul 2016 10:24:11 -0700

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".
---
 touch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
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);
 
-- 
2.6.2
Received on Fri Jul 08 2016 - 19:24:11 CEST

This archive was generated by hypermail 2.3.0 : Fri Jul 08 2016 - 19:36:31 CEST