summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPádraig Brady <P@draigBrady.com>2011-01-14 08:46:21 +0000
committerPádraig Brady <P@draigBrady.com>2011-01-29 23:33:25 +0000
commit32626bde6d68508109a99dfe0a089a0025f56085 (patch)
tree5f45efbab1684bbf57184dbdc82e7f7ebb6cf151 /src
parentd4db0cb1827730ed5536c12c0ebd024283b3a4db (diff)
downloadcoreutils-32626bde6d68508109a99dfe0a089a0025f56085.tar.xz
join: ensure --header skips the order check with empty files
* src/join.c: Skip the header even if one of the files is empty. * tests/misc/join: Add a test case. * NEWS: Mention the fix
Diffstat (limited to 'src')
-rw-r--r--src/join.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/join.c b/src/join.c
index bf7e908af..ab7625183 100644
--- a/src/join.c
+++ b/src/join.c
@@ -648,13 +648,17 @@ join (FILE *fp1, FILE *fp2)
autocount_2 = seq2.count ? seq2.lines[0]->nfields : 0;
}
- if (join_header_lines && seq1.count && seq2.count)
+ if (join_header_lines && (seq1.count || seq2.count))
{
- prjoin (seq1.lines[0], seq2.lines[0]);
+ struct line const *hline1 = seq1.count ? seq1.lines[0] : &uni_blank;
+ struct line const *hline2 = seq2.count ? seq2.lines[0] : &uni_blank;
+ prjoin (hline1, hline2);
prevline[0] = NULL;
prevline[1] = NULL;
- advance_seq (fp1, &seq1, true, 1);
- advance_seq (fp2, &seq2, true, 2);
+ if (seq1.count)
+ advance_seq (fp1, &seq1, true, 1);
+ if (seq2.count)
+ advance_seq (fp2, &seq2, true, 2);
}
while (seq1.count && seq2.count)