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".
This commit is contained in:
Michael Forney 2016-07-08 10:24:11 -07:00 committed by sin
parent a211649cfd
commit 0941c9ab2c

View File

@ -38,7 +38,7 @@ touch(const char *file)
return; 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); eprintf("open %s:", file);
close(fd); close(fd);