Include "full-read.h".

(bytes_split, lines_split, line_bytes_split): Use full_read,
not safe_read.   The way split was using the latter, a short read
could cause split to terminate before EOF.

(bytes_split): Remove unnecessary `else' after break.
(lines_split): Likewise.  and correct misleading indentation.
This commit is contained in:
Jim Meyering committed 2003-02-19 14:28:50 +00:00
1 parent d0944f6e8b
commit 23f6d41f94
1 file changed
+20 -21
+20 -21
View File
@@ -1,5 +1,5 @@
/* split.c -- split a file into pieces. /* split.c -- split a file into pieces.
Copyright (C) 88, 91, 1995-2002 Free Software Foundation, Inc. Copyright (C) 88, 91, 1995-2003 Free Software Foundation, Inc.
This program is free software; you can redistribute it and/or modify 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 it under the terms of the GNU General Public License as published by
@@ -31,6 +31,7 @@
#include "closeout.h" #include "closeout.h"
#include "dirname.h" #include "dirname.h"
#include "error.h" #include "error.h"
#include "full-read.h"
#include "full-write.h" #include "full-write.h"
#include "posixver.h" #include "posixver.h"
#include "safe-read.h" #include "safe-read.h"
@@ -209,7 +210,7 @@ bytes_split (size_t nchars, char *buf, size_t bufsize)
do do
{ {
n_read = safe_read (input_desc, buf, bufsize); n_read = full_read (input_desc, buf, bufsize);
if (n_read == SAFE_READ_ERROR) if (n_read == SAFE_READ_ERROR)
error (EXIT_FAILURE, errno, "%s", infile); error (EXIT_FAILURE, errno, "%s", infile);
bp_out = buf; bp_out = buf;
@@ -226,14 +227,12 @@ bytes_split (size_t nchars, char *buf, size_t bufsize)
} }
break; break;
} }
else
{ cwrite (new_file_flag, bp_out, to_write);
cwrite (new_file_flag, bp_out, to_write); bp_out += to_write;
bp_out += to_write; to_read -= to_write;
to_read -= to_write; new_file_flag = 1;
new_file_flag = 1; to_write = nchars;
to_write = nchars;
}
} }
} }
while (n_read == bufsize); while (n_read == bufsize);
@@ -252,7 +251,7 @@ lines_split (size_t nlines, char *buf, size_t bufsize)
do do
{ {
n_read = safe_read (input_desc, buf, bufsize); n_read = full_read (input_desc, buf, bufsize);
if (n_read == SAFE_READ_ERROR) if (n_read == SAFE_READ_ERROR)
error (EXIT_FAILURE, errno, "%s", infile); error (EXIT_FAILURE, errno, "%s", infile);
bp = bp_out = buf; bp = bp_out = buf;
@@ -271,15 +270,15 @@ lines_split (size_t nlines, char *buf, size_t bufsize)
} }
break; break;
} }
else
++bp; ++bp;
if (++n >= nlines) if (++n >= nlines)
{ {
cwrite (new_file_flag, bp_out, bp - bp_out); cwrite (new_file_flag, bp_out, bp - bp_out);
bp_out = bp; bp_out = bp;
new_file_flag = 1; new_file_flag = 1;
n = 0; n = 0;
} }
} }
} }
while (n_read == bufsize); while (n_read == bufsize);
@@ -302,7 +301,7 @@ line_bytes_split (size_t nchars)
{ {
/* Fill up the full buffer size from the input file. */ /* Fill up the full buffer size from the input file. */
n_read = safe_read (input_desc, buf + n_buffered, nchars - n_buffered); n_read = full_read (input_desc, buf + n_buffered, nchars - n_buffered);
if (n_read == SAFE_READ_ERROR) if (n_read == SAFE_READ_ERROR)
error (EXIT_FAILURE, errno, "%s", infile); error (EXIT_FAILURE, errno, "%s", infile);