bug-coreutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

split -C sometimes creates empty files


From: Paul Eggert
Subject: split -C sometimes creates empty files
Date: Wed, 11 Apr 2007 14:23:51 -0700
User-agent: Gnus/5.1008 (Gnus v5.10.8) Emacs/21.4 (gnu/linux)

'split -C N' creates an extra empty file if the last output file
contains exactly N bytes.  Here is a patch.

2007-04-11  Paul Eggert  <address@hidden>

        * src/split.c (line_bytes_split): Don't create an empty line
        afterwards if the last buffer happens to be exactly full.
        * tests/misc/split-fail: Add a test case for this.

diff --git a/src/split.c b/src/split.c
index 2fc6ecf..207cc13 100644
--- a/src/split.c
+++ b/src/split.c
@@ -336,7 +336,11 @@ line_bytes_split (size_t n_bytes)

       n_buffered += n_read;
       if (n_buffered != n_bytes)
-       eof = true;
+       {
+         if (n_buffered == 0)
+           break;
+         eof = true;
+       }

       /* Find where to end this chunk.  */
       bp = buf + n_buffered;
diff --git a/tests/misc/split-fail b/tests/misc/split-fail
index 70435b4..8cdfe64 100755
--- a/tests/misc/split-fail
+++ b/tests/misc/split-fail
@@ -1,7 +1,7 @@
 #!/bin/sh
 # split must fail when given length/count of zero.

-# Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc.
+# Copyright (C) 2003, 2004, 2005, 2006, 2007 Free Software Foundation, Inc.

 # This program is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
@@ -47,6 +47,12 @@ split -b 0 in 2> /dev/null && fail=1
 split -C 0 in 2> /dev/null && fail=1
 split -l 0 in 2> /dev/null && fail=1

+# Make sure -C doesn't create empty files.
+rm -f x?? || fail=1
+echo x | split -C 1 || fail=1
+test -f xaa && test -f xab || fail=1
+test -f xac && fail=1
+
 # Make sure that the obsolete -N notation still works
 split -1 in 2> /dev/null || fail=1

M ChangeLog
M src/split.c
M tests/misc/split-fail
Committed as c06c8614c16cade9f52440adc546723a8db21d5d




reply via email to

[Prev in Thread] Current Thread [Next in Thread]