Use the proper octal mode naming instead of random decimal
crud, and don't reset the mode after the create with fchmod:
the whole point was to let "umask" do its thing.
Duh.
- mode = (mode & 0100) ? 777 : 666;
+ mode = (mode & 0100) ? 0777 : 0666;
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);
if (fd < 0) {
if (errno == ENOENT) {
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);
if (fd < 0) {
if (errno == ENOENT) {
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);
}
}
fd = open(path, O_WRONLY | O_TRUNC | O_CREAT, mode);
}
}
- if (fd >= 0)
- fchmod(fd, mode);