diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 2015-04-02 12:48:29 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 2015-04-02 12:48:29 +0000 |
commit | 3fa3d16ff5d144f4b0d57ae0eb10ea39e134d24c (patch) | |
tree | af1ce2f6ad890f1d7fc4848a38b3b358efd1abe1 | |
parent | ae425576c9b681190ae752db0fc8036a00ba141c (diff) |
No need for the umask() dance now that temp files are created
with mkstemp(). Also remove useless else after a return.
-rw-r--r-- | usr.bin/sort/file.c | 49 |
1 files changed, 19 insertions, 30 deletions
diff --git a/usr.bin/sort/file.c b/usr.bin/sort/file.c index ad55db8ede2..cd7a2aa1886 100644 --- a/usr.bin/sort/file.c +++ b/usr.bin/sort/file.c @@ -1,4 +1,4 @@ -/* $OpenBSD: file.c,v 1.16 2015/04/02 12:21:18 millert Exp $ */ +/* $OpenBSD: file.c,v 1.17 2015/04/02 12:48:28 millert Exp $ */ /*- * Copyright (C) 2009 Gabor Kovesdan <gabor@FreeBSD.org> @@ -482,41 +482,30 @@ openfile(const char *fn, const char *mode) { FILE *file; - if (strcmp(fn, "-") == 0) { - return (mode && mode[0] == 'r') ? stdin : stdout; - } else { - mode_t orig_file_mask = 0; - int is_tmp = file_is_tmp(fn); - - if (is_tmp && (mode[0] == 'w')) - orig_file_mask = umask(S_IWGRP | S_IWOTH | - S_IRGRP | S_IROTH); + if (strcmp(fn, "-") == 0) + return (mode[0] == 'r') ? stdin : stdout; - if (is_tmp && (compress_program != NULL)) { - char *cmd; + if (file_is_tmp(fn) && (compress_program != NULL)) { + char *cmd; - fflush(stdout); + fflush(stdout); - if (mode[0] == 'r') - sort_asprintf(&cmd, "%s -d < %s", - compress_program, fn); - else if (mode[0] == 'w') - sort_asprintf(&cmd, "%s > %s", - compress_program, fn); - else - err(2, "Wrong file mode"); + if (mode[0] == 'r') + sort_asprintf(&cmd, "%s -d < %s", + compress_program, fn); + else if (mode[0] == 'w') + sort_asprintf(&cmd, "%s > %s", + compress_program, fn); + else + err(2, "invalid file mode"); - if ((file = popen(cmd, mode)) == NULL) - err(2, NULL); + if ((file = popen(cmd, mode)) == NULL) + err(2, "%s", compress_program); - sort_free(cmd); + sort_free(cmd); - } else if ((file = fopen(fn, mode)) == NULL) - err(2, "%s", fn); - - if (is_tmp && (mode[0] == 'w')) - umask(orig_file_mask); - } + } else if ((file = fopen(fn, mode)) == NULL) + err(2, "%s", fn); return file; } |