X-Git-Url: https://git.saurik.com/apple/system_cmds.git/blobdiff_plain/709a58224ea43109dc10bfd6a67de1e432174197..34d340d711a2b033f5da480ed7b5eb147679a588:/mkfile.tproj/mkfile.c diff --git a/mkfile.tproj/mkfile.c b/mkfile.tproj/mkfile.c index 4aff548..0965ef5 100644 --- a/mkfile.tproj/mkfile.c +++ b/mkfile.tproj/mkfile.c @@ -41,6 +41,7 @@ #include #include #include +#include #define BF_SZ 512 /* Size of write chunks */ @@ -142,9 +143,12 @@ create_file(file_name, size, empty, verbose) char buff[BF_SZ]; int fd, bytes_written = BF_SZ; quad_t i; - mode_t mode; + mode_t mode = S_IRUSR | S_IWUSR; - if ((fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC )) == -1) + /* If superuser, then set sticky bit */ + if (!geteuid()) mode |= S_ISVTX; + + if ((fd = open(file_name, O_RDWR | O_CREAT | O_TRUNC, mode)) == -1) err(1, NULL); @@ -176,17 +180,11 @@ create_file(file_name, size, empty, verbose) } } + if (fchmod(fd, mode)) /* Change permissions */ + err_rm(file_name, NULL); - mode = S_IRUSR | S_IWUSR; - /* If superuser, then set sticky bit */ - if (! geteuid()) - mode |= S_ISVTX; - - if (fchmod(fd, mode)) /* Change permissions */ - err_rm(file_name, NULL); - - if ((close(fd)) == -1) - err_rm(file_name, NULL); + if ((close(fd)) == -1) + err_rm(file_name, NULL); if (verbose) (void)fprintf(stderr, "%s %qd bytes\n", file_name, size);