From: Jim Meyering Date: Tue, 13 Mar 2001 08:48:57 +0000 (+0000) Subject: (sort): If all the input files are empty, create an empty output file. X-Git-Tag: FILEUTILS-4_0_42~47 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=811ade551454d824541555edb3ffcfc5ef4e3ee0;p=thirdparty%2Fcoreutils.git (sort): If all the input files are empty, create an empty output file. --- diff --git a/src/sort.c b/src/sort.c index 981c97f062..f9534a1ec3 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1866,6 +1866,7 @@ sort (char **files, int nfiles, char const *output_file) { struct buffer buf; int n_temp_files = 0; + int output_file_created = 0; buf.alloc = 0; @@ -1909,6 +1910,7 @@ sort (char **files, int nfiles, char const *output_file) xfclose (fp, file); tfp = xfopen (output_file, "w"); temp_output = output_file; + output_file_created = 1; } else { @@ -1928,7 +1930,7 @@ sort (char **files, int nfiles, char const *output_file) xfclose (tfp, temp_output); - if (! n_temp_files) + if (output_file_created) goto finish; } xfclose (fp, file); @@ -1937,7 +1939,7 @@ sort (char **files, int nfiles, char const *output_file) finish: free (buf.buf); - if (n_temp_files) + if (! output_file_created) { int i = n_temp_files; struct tempnode *node;