sort: deindent openfile

This commit is contained in:
Baptiste Daroussin 2022-10-13 10:31:08 +02:00
parent f079ef8aa4
commit 958b0d4642

View File

@ -527,46 +527,45 @@ openfile(const char *fn, const char *mode)
{ {
FILE *file; FILE *file;
if (strcmp(fn, "-") == 0) { if (strcmp(fn, "-") == 0)
return ((mode && mode[0] == 'r') ? stdin : stdout); 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')) mode_t orig_file_mask = 0;
orig_file_mask = umask(S_IWGRP | S_IWOTH | int is_tmp = file_is_tmp(fn);
S_IRGRP | S_IROTH);
if (is_tmp && (compress_program != NULL)) { if (is_tmp && (mode[0] == 'w'))
char *cmd; orig_file_mask = umask(S_IWGRP | S_IWOTH |
size_t cmdsz; S_IRGRP | S_IROTH);
cmdsz = strlen(fn) + 128; if (is_tmp && (compress_program != NULL)) {
cmd = sort_malloc(cmdsz); char *cmd;
size_t cmdsz;
fflush(stdout); cmdsz = strlen(fn) + 128;
cmd = sort_malloc(cmdsz);
if (mode[0] == 'r') fflush(stdout);
snprintf(cmd, cmdsz - 1, "cat %s | %s -d",
fn, compress_program);
else if (mode[0] == 'w')
snprintf(cmd, cmdsz - 1, "%s > %s",
compress_program, fn);
else
err(2, "%s", getstr(7));
if ((file = popen(cmd, mode)) == NULL) if (mode[0] == 'r')
err(2, NULL); snprintf(cmd, cmdsz - 1, "cat %s | %s -d",
fn, compress_program);
else if (mode[0] == 'w')
snprintf(cmd, cmdsz - 1, "%s > %s",
compress_program, fn);
else
err(2, "%s", getstr(7));
sort_free(cmd); if ((file = popen(cmd, mode)) == NULL)
err(2, NULL);
} else sort_free(cmd);
if ((file = fopen(fn, mode)) == NULL)
err(2, NULL);
if (is_tmp && (mode[0] == 'w')) } else
umask(orig_file_mask); if ((file = fopen(fn, mode)) == NULL)
} err(2, NULL);
if (is_tmp && (mode[0] == 'w'))
umask(orig_file_mask);
return (file); return (file);
} }