version 1.50, 2015/03/30 22:20:53 |
version 1.51, 2015/03/31 11:46:26 |
|
|
{ false, false, false, false, false, false }; |
{ false, false, false, false, false, false }; |
|
|
result = 0; |
result = 0; |
outfile = sort_strdup("-"); |
outfile = "-"; |
real_outfile = NULL; |
real_outfile = NULL; |
|
|
struct sort_mods *sm = &default_sort_mods_object; |
struct sort_mods *sm = &default_sort_mods_object; |
|
|
|
|
set_signal_handler(); |
set_signal_handler(); |
|
|
|
atexit(clear_tmp_files); |
|
|
set_hw_params(); |
set_hw_params(); |
set_locale(); |
set_locale(); |
set_tmpdir(); |
set_tmpdir(); |
|
|
sort_opts_vals.mflag = true; |
sort_opts_vals.mflag = true; |
break; |
break; |
case 'o': |
case 'o': |
sort_free(outfile); |
outfile = optarg; |
outfile = sort_strdup(optarg); |
|
break; |
break; |
case 's': |
case 's': |
sort_opts_vals.sflag = true; |
sort_opts_vals.sflag = true; |
|
|
set_random_seed(); |
set_random_seed(); |
|
|
/* Case when the outfile equals one of the input files: */ |
/* Case when the outfile equals one of the input files: */ |
if (strcmp(outfile, "-")) { |
if (strcmp(outfile, "-") != 0) { |
int i; |
struct stat sb; |
|
int fd, i; |
|
|
for (i = 0; i < argc; ++i) { |
for (i = 0; i < argc; ++i) { |
if (strcmp(argv[i], outfile) == 0) { |
if (strcmp(argv[i], outfile) == 0) { |
real_outfile = sort_strdup(outfile); |
if (stat(outfile, &sb) == -1) |
for (;;) { |
err(2, "%s", outfile); |
const size_t size = strlen(outfile) + strlen(".tmp") + 1; |
if (access(outfile, W_OK) == -1) |
outfile = sort_realloc(outfile, size); |
err(2, "%s", outfile); |
strlcat(outfile, ".tmp", size); |
real_outfile = outfile; |
if (access(outfile, F_OK) < 0) |
sort_asprintf(&outfile, "%s.XXXXXXXXXX", |
break; |
real_outfile); |
} |
if ((fd = mkstemp(outfile)) == -1 || |
|
fchmod(fd, sb.st_mode & ALLPERMS) == -1) |
|
err(2, "%s", outfile); |
|
close(fd); |
tmp_file_atexit(outfile); |
tmp_file_atexit(outfile); |
|
break; |
} |
} |
} |
} |
} |
} |
|
|
} |
} |
|
|
if (real_outfile) { |
if (real_outfile) { |
unlink(real_outfile); |
|
if (rename(outfile, real_outfile) < 0) |
if (rename(outfile, real_outfile) < 0) |
err(2, "%s", real_outfile); |
err(2, "%s", real_outfile); |
sort_free(real_outfile); |
sort_free(outfile); |
} |
} |
|
|
sort_free(outfile); |
|
|
|
return result; |
return result; |
} |
} |