[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Split -b Question
From: |
Paul Eggert |
Subject: |
Re: Split -b Question |
Date: |
08 Apr 2003 13:51:39 -0700 |
User-agent: |
Gnus/5.09 (Gnus v5.9.0) Emacs/21.3 |
Luke Hassell <address@hidden> writes:
> I must have missed something obvious.
No, you haven't. split doesn't support large files in coreutils 5.0;
this has been a FIXME for a while, I think. Here's a patch.
2003-04-08 Paul Eggert <address@hidden>
* src/split.c: Add support for large files.
Include "inttostr.h".
(bytes_split, lines_split, line_bytes_split, main):
Use uintmax_t, not size_t, for file sizes.
Use umaxtostr to print file sizes.
--- split.c 2003/03/11 20:44:40 5.0
+++ split.c 2003/04/08 20:46:46
@@ -33,6 +33,7 @@
#include "error.h"
#include "full-read.h"
#include "full-write.h"
+#include "inttostr.h"
#include "posixver.h"
#include "safe-read.h"
#include "xstrtol.h"
@@ -200,12 +201,12 @@ cwrite (int new_file_flag, const char *b
Use buffer BUF, whose size is BUFSIZE. */
static void
-bytes_split (size_t nchars, char *buf, size_t bufsize)
+bytes_split (uintmax_t nchars, char *buf, size_t bufsize)
{
size_t n_read;
int new_file_flag = 1;
size_t to_read;
- size_t to_write = nchars;
+ uintmax_t to_write = nchars;
char *bp_out;
do
@@ -227,12 +228,15 @@ bytes_split (size_t nchars, char *buf, s
}
break;
}
-
- cwrite (new_file_flag, bp_out, to_write);
- bp_out += to_write;
- to_read -= to_write;
- new_file_flag = 1;
- to_write = nchars;
+ else
+ {
+ size_t w = to_write;
+ cwrite (new_file_flag, bp_out, w);
+ bp_out += w;
+ to_read -= w;
+ new_file_flag = 1;
+ to_write = nchars;
+ }
}
}
while (n_read == bufsize);
@@ -242,12 +246,12 @@ bytes_split (size_t nchars, char *buf, s
Use buffer BUF, whose size is BUFSIZE. */
static void
-lines_split (size_t nlines, char *buf, size_t bufsize)
+lines_split (uintmax_t nlines, char *buf, size_t bufsize)
{
size_t n_read;
char *bp, *bp_out, *eob;
int new_file_flag = 1;
- size_t n = 0;
+ uintmax_t n = 0;
do
{
@@ -289,13 +293,14 @@ lines_split (size_t nlines, char *buf, s
where lines longer than NCHARS bytes occur. */
static void
-line_bytes_split (size_t nchars)
+line_bytes_split (uintmax_t nchars)
{
size_t n_read;
char *bp;
int eof = 0;
size_t n_buffered = 0;
- char *buf = (char *) xmalloc (nchars);
+ size_t allocated = nchars;
+ char *buf = (char *) xmalloc (allocated);
do
{
@@ -347,14 +352,14 @@ int
main (int argc, char **argv)
{
struct stat stat_buf;
- size_t num; /* numeric argument from command line */
+ uintmax_t num; /* numeric argument from command line */
enum
{
type_undef, type_bytes, type_byteslines, type_lines, type_digits
} split_type = type_undef;
size_t in_blk_size; /* optimal block size of input file device */
char *buf; /* file i/o buffer */
- size_t accum = 0;
+ uintmax_t accum = 0;
int c;
int digits_optind = 0;
@@ -374,7 +379,6 @@ main (int argc, char **argv)
{
/* This is the argv-index of the option we will read next. */
int this_optind = optind ? optind : 1;
- long int tmp_long;
c = getopt_long (argc, argv, "0123456789C:a:b:l:", longopts, NULL);
if (c == -1)
@@ -402,39 +406,34 @@ main (int argc, char **argv)
if (split_type != type_undef)
FAIL_ONLY_ONE_WAY ();
split_type = type_bytes;
- if (xstrtol (optarg, NULL, 10, &tmp_long, "bkm") != LONGINT_OK
- || tmp_long < 0 || tmp_long > INT_MAX)
+ if (xstrtoumax (optarg, NULL, 10, &accum, "bkm") != LONGINT_OK)
{
error (0, 0, _("%s: invalid number of bytes"), optarg);
usage (EXIT_FAILURE);
}
- accum = /* FIXME: */ (int) tmp_long;
break;
case 'l':
if (split_type != type_undef)
FAIL_ONLY_ONE_WAY ();
split_type = type_lines;
- if (xstrtol (optarg, NULL, 10, &tmp_long, "") != LONGINT_OK
- || tmp_long < 0 || tmp_long > INT_MAX)
+ if (xstrtoumax (optarg, NULL, 10, &accum, "") != LONGINT_OK)
{
error (0, 0, _("%s: invalid number of lines"), optarg);
usage (EXIT_FAILURE);
}
- accum = /* FIXME */ (int) tmp_long;
break;
case 'C':
if (split_type != type_undef)
FAIL_ONLY_ONE_WAY ();
split_type = type_byteslines;
- if (xstrtol (optarg, NULL, 10, &tmp_long, "bkm") != LONGINT_OK
- || tmp_long < 0 || tmp_long > INT_MAX)
+ if (xstrtoumax (optarg, NULL, 10, &accum, "bkm") != LONGINT_OK
+ || SIZE_MAX < accum)
{
error (0, 0, _("%s: invalid number of bytes"), optarg);
usage (EXIT_FAILURE);
}
- accum = /* FIXME */ (int) tmp_long;
break;
case '0':
@@ -467,7 +466,9 @@ main (int argc, char **argv)
if (digits_optind && 200112 <= posix2_version ())
{
- error (0, 0, _("`-%d' option is obsolete; use `-l %d'"), accum, accum);
+ char buf[INT_BUFSIZE_BOUND (uintmax_t)];
+ char const *a = umaxtostr (accum, buf);
+ error (0, 0, _("`-%s' option is obsolete; use `-l %s'"), a, a);
usage (EXIT_FAILURE);
}