1992-11-08 02:50:43 +00:00
|
|
|
|
/* split.c -- split a file into pieces.
|
2008-02-06 08:25:24 +01:00
|
|
|
|
Copyright (C) 1988, 1991, 1995-2008 Free Software Foundation, Inc.
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
2007-07-23 14:35:58 +02:00
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
1992-11-08 02:50:43 +00:00
|
|
|
|
it under the terms of the GNU General Public License as published by
|
2007-07-23 14:35:58 +02:00
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
|
|
(at your option) any later version.
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
2007-07-23 14:35:58 +02:00
|
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. */
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
|
|
|
|
|
/* By tege@sics.se, with rms.
|
|
|
|
|
|
|
|
|
|
|
|
To do:
|
|
|
|
|
|
* Implement -t CHAR or -t REGEX to specify break characters other
|
|
|
|
|
|
than newline. */
|
|
|
|
|
|
|
1993-10-21 22:08:53 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
|
1992-11-08 02:50:43 +00:00
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
|
|
#include <sys/types.h>
|
1995-10-31 12:52:29 +00:00
|
|
|
|
|
1992-11-08 02:50:43 +00:00
|
|
|
|
#include "system.h"
|
1994-12-16 05:42:47 +00:00
|
|
|
|
#include "error.h"
|
2005-07-03 07:20:33 +00:00
|
|
|
|
#include "fd-reopen.h"
|
|
|
|
|
|
#include "fcntl--.h"
|
2003-02-19 14:28:50 +00:00
|
|
|
|
#include "full-read.h"
|
2001-08-31 07:46:28 +00:00
|
|
|
|
#include "full-write.h"
|
2003-04-09 14:37:47 +00:00
|
|
|
|
#include "inttostr.h"
|
2004-06-21 15:03:35 +00:00
|
|
|
|
#include "quote.h"
|
1998-04-11 18:24:09 +00:00
|
|
|
|
#include "safe-read.h"
|
1999-03-04 05:36:10 +00:00
|
|
|
|
#include "xstrtol.h"
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
1999-04-03 05:01:48 +00:00
|
|
|
|
/* The official name of this program (e.g., no `g' prefix). */
|
|
|
|
|
|
#define PROGRAM_NAME "split"
|
|
|
|
|
|
|
use gnulib's proper_name_utf8 function, but *not* proper_name
* bootstrap.conf (gnulib_modules): Add propername.
(XGETTEXT_OPTIONS): Add options to tell xgettext about the functions.
* src/cat.c, src/cp.c, src/df.c, src/du.c, src/split.c:
Mark Torbjörn Granlund's name.
* src/ptx.c: Mark François Pinard's name.
Use "TRANSLATORS:" comment marker, rather than "Note to translators:".
* src/system.h: Include propername.h.
(proper_name): Define away.
* src/Makefile.am (cat_LDADD, df_LDADD, du_LDADD, ptx_LDADD, split_LDADD):
Initialize, so we can...
(cat_LDADD, cp_LDADD, df_LDADD, du_LDADD, ptx_LDADD, split_LDADD):
...Use "+=" to append $(LIBICONV) for each program that uses
proper_name_utf8.
2008-05-19 16:14:13 +02:00
|
|
|
|
#define AUTHORS \
|
|
|
|
|
|
proper_name_utf8 ("Torbjorn Granlund", "Torbj\303\266rn Granlund"), \
|
2008-05-19 16:43:32 +02:00
|
|
|
|
proper_name ("Richard M. Stallman")
|
1999-04-03 05:22:05 +00:00
|
|
|
|
|
2002-02-12 15:46:34 +00:00
|
|
|
|
#define DEFAULT_SUFFIX_LENGTH 2
|
|
|
|
|
|
|
1992-11-08 02:50:43 +00:00
|
|
|
|
/* Base name of output files. */
|
2002-02-12 15:44:16 +00:00
|
|
|
|
static char const *outbase;
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
2002-02-12 15:44:16 +00:00
|
|
|
|
/* Name of output files. */
|
|
|
|
|
|
static char *outfile;
|
2002-02-12 15:46:34 +00:00
|
|
|
|
|
1992-11-08 02:50:43 +00:00
|
|
|
|
/* Pointer to the end of the prefix in OUTFILE.
|
|
|
|
|
|
Suffixes are inserted here. */
|
1992-11-08 20:19:58 +00:00
|
|
|
|
static char *outfile_mid;
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
2002-02-12 15:44:16 +00:00
|
|
|
|
/* Length of OUTFILE's suffix. */
|
2002-02-12 15:46:34 +00:00
|
|
|
|
static size_t suffix_length = DEFAULT_SUFFIX_LENGTH;
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
2003-08-09 09:16:39 +00:00
|
|
|
|
/* Alphabet of characters to use in suffix. */
|
|
|
|
|
|
static char const *suffix_alphabet = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
|
|
1992-11-08 02:50:43 +00:00
|
|
|
|
/* Name of input file. May be "-". */
|
1992-11-08 20:19:58 +00:00
|
|
|
|
static char *infile;
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
|
|
|
|
|
/* Descriptor on which output file is open. */
|
1992-11-08 20:19:58 +00:00
|
|
|
|
static int output_desc;
|
1993-04-29 05:26:22 +00:00
|
|
|
|
|
2004-09-21 22:13:53 +00:00
|
|
|
|
/* If true, print a diagnostic on standard error just before each
|
1995-11-07 04:56:08 +00:00
|
|
|
|
output file is opened. */
|
2004-09-21 22:13:53 +00:00
|
|
|
|
static bool verbose;
|
|
|
|
|
|
|
|
|
|
|
|
/* For long options that have no equivalent short option, use a
|
|
|
|
|
|
non-character as a pseudo short option, starting with CHAR_MAX + 1. */
|
|
|
|
|
|
enum
|
|
|
|
|
|
{
|
|
|
|
|
|
VERBOSE_OPTION = CHAR_MAX + 1
|
|
|
|
|
|
};
|
1995-11-07 04:56:08 +00:00
|
|
|
|
|
1993-04-29 05:26:22 +00:00
|
|
|
|
static struct option const longopts[] =
|
|
|
|
|
|
{
|
|
|
|
|
|
{"bytes", required_argument, NULL, 'b'},
|
|
|
|
|
|
{"lines", required_argument, NULL, 'l'},
|
|
|
|
|
|
{"line-bytes", required_argument, NULL, 'C'},
|
2002-02-12 15:44:16 +00:00
|
|
|
|
{"suffix-length", required_argument, NULL, 'a'},
|
2003-08-09 09:16:39 +00:00
|
|
|
|
{"numeric-suffixes", no_argument, NULL, 'd'},
|
2004-09-21 22:13:53 +00:00
|
|
|
|
{"verbose", no_argument, NULL, VERBOSE_OPTION},
|
1999-04-04 15:44:26 +00:00
|
|
|
|
{GETOPT_HELP_OPTION_DECL},
|
|
|
|
|
|
{GETOPT_VERSION_OPTION_DECL},
|
1993-04-29 05:26:22 +00:00
|
|
|
|
{NULL, 0, NULL, 0}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
1999-01-14 18:25:16 +00:00
|
|
|
|
void
|
1996-10-13 17:53:47 +00:00
|
|
|
|
usage (int status)
|
1992-11-08 02:50:43 +00:00
|
|
|
|
{
|
2004-01-21 23:45:13 +00:00
|
|
|
|
if (status != EXIT_SUCCESS)
|
1995-08-07 14:57:29 +00:00
|
|
|
|
fprintf (stderr, _("Try `%s --help' for more information.\n"),
|
1993-10-23 15:37:19 +00:00
|
|
|
|
program_name);
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
1995-08-07 14:57:29 +00:00
|
|
|
|
printf (_("\
|
1993-10-23 15:37:19 +00:00
|
|
|
|
Usage: %s [OPTION] [INPUT [PREFIX]]\n\
|
1995-08-07 14:57:29 +00:00
|
|
|
|
"),
|
1993-10-23 15:37:19 +00:00
|
|
|
|
program_name);
|
2001-11-11 14:47:28 +00:00
|
|
|
|
fputs (_("\
|
1995-05-13 18:34:54 +00:00
|
|
|
|
Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default\n\
|
2004-12-20 20:00:44 +00:00
|
|
|
|
size is 1000 lines, and default PREFIX is `x'. With no INPUT, or when INPUT\n\
|
|
|
|
|
|
is -, read standard input.\n\
|
1993-10-23 15:37:19 +00:00
|
|
|
|
\n\
|
2001-11-23 19:58:23 +00:00
|
|
|
|
"), stdout);
|
|
|
|
|
|
fputs (_("\
|
2001-11-04 09:43:16 +00:00
|
|
|
|
Mandatory arguments to long options are mandatory for short options too.\n\
|
2001-11-23 19:58:23 +00:00
|
|
|
|
"), stdout);
|
2002-02-12 15:46:34 +00:00
|
|
|
|
fprintf (stdout, _("\
|
|
|
|
|
|
-a, --suffix-length=N use suffixes of length N (default %d)\n\
|
1993-10-24 20:00:39 +00:00
|
|
|
|
-b, --bytes=SIZE put SIZE bytes per output file\n\
|
1996-11-23 22:06:55 +00:00
|
|
|
|
-C, --line-bytes=SIZE put at most SIZE bytes of lines per output file\n\
|
2003-08-09 09:16:39 +00:00
|
|
|
|
-d, --numeric-suffixes use numeric suffixes instead of alphabetic\n\
|
1993-10-24 20:00:39 +00:00
|
|
|
|
-l, --lines=NUMBER put NUMBER lines per output file\n\
|
2002-02-12 15:46:34 +00:00
|
|
|
|
"), DEFAULT_SUFFIX_LENGTH);
|
Add more support for POSIX 1003.1-2001, which requires removal for
support of obsolete "-N" option syntax in expand, head, fold,
split, tail, unexpand, uniq, and which prohibits options with
optional arguments in od and pr.
(usage): Document this.
(main): Check for obsolete options.
(shortopts): New constant.
(main): Use -1, not EOF, for getopt_long.
2002-02-02 09:40:50 +00:00
|
|
|
|
fputs (_("\
|
2008-02-06 08:25:24 +01:00
|
|
|
|
--verbose print a diagnostic just before each\n\
|
|
|
|
|
|
output file is opened\n\
|
2001-11-23 19:58:23 +00:00
|
|
|
|
"), stdout);
|
2001-12-01 17:41:25 +00:00
|
|
|
|
fputs (HELP_OPTION_DESCRIPTION, stdout);
|
|
|
|
|
|
fputs (VERSION_OPTION_DESCRIPTION, stdout);
|
2001-11-23 19:58:23 +00:00
|
|
|
|
fputs (_("\
|
1993-10-23 15:37:19 +00:00
|
|
|
|
\n\
|
The following commands and options now support the standard size
suffixes kB, M, MB, G, GB, and so on for T, P, Y, Z, and Y:
head -c, head -n, od -j, od -N, od -S, split -b, split -C,
tail -c, tail -n.
* doc/coreutils.texi (od invocation, head invocation, tail invocation):
Document support for new size suffixes.
(head invocation, tail invocation):
Document that -n uses the same suffixes as -c.
(tail invocation): More-clearly document what leading "+" does.
* src/head.c (usage, string_to_integer): Support new suffixes.
* src/od.c (usage, main): Likewise.
* src/split.c (usage, main): Likewise.
* src/tail.c (usage, parse_options): Likewise.
Prompted by a patch from Evan Hunt.
2007-05-03 13:45:26 +02:00
|
|
|
|
SIZE may have a multiplier suffix:\n\
|
|
|
|
|
|
b 512, kB 1000, K 1024, MB 1000*1000, M 1024*1024,\n\
|
|
|
|
|
|
GB 1000*1000*1000, G 1024*1024*1024, and so on for T, P, E, Z, Y.\n\
|
2001-11-11 14:47:28 +00:00
|
|
|
|
"), stdout);
|
Help translators include translation team's web or email address.
* src/system.h (emit_bug_reporting_address): New function.
* src/base64.c: Use it rather than a literal printf.
* src/basename.c, src/cat.c, src/chgrp.c, src/chmod.c:
* src/chown.c, src/chroot.c, src/cksum.c, src/comm.c, src/cp.c:
* src/csplit.c, src/cut.c, src/date.c, src/dd.c, src/df.c:
* src/dircolors.c, src/dirname.c, src/du.c, src/echo.c, src/env.c:
* src/expand.c, src/expr.c, src/factor.c, src/fmt.c, src/fold.c:
* src/head.c, src/hostid.c, src/hostname.c, src/id.c, src/install.c:
* src/join.c, src/kill.c, src/link.c, src/ln.c, src/logname.c:
* src/ls.c, src/md5sum.c, src/mkdir.c, src/mkfifo.c, src/mknod.c:
* src/mv.c, src/nice.c, src/nl.c, src/nohup.c, src/od.c:
* src/paste.c, src/pathchk.c, src/pinky.c, src/pr.c, src/printenv.c:
* src/printf.c, src/ptx.c, src/pwd.c, src/readlink.c, src/rm.c:
* src/rmdir.c, src/seq.c, src/setuidgid.c, src/shred.c, src/shuf.c:
* src/sleep.c, src/sort.c, src/split.c, src/stat.c, src/stty.c:
* src/su.c, src/sum.c, src/sync.c, src/system.h, src/tac.c:
* src/tail.c, src/tee.c, src/test.c, src/touch.c, src/tr.c:
* src/true.c, src/tsort.c, src/tty.c, src/uname.c, src/unexpand.c:
* src/uniq.c, src/unlink.c, src/uptime.c, src/users.c, src/wc.c:
* src/who.c, src/whoami.c, src/yes.c: Likewise.
2007-03-28 08:50:29 +02:00
|
|
|
|
emit_bug_reporting_address ();
|
1993-10-23 15:37:19 +00:00
|
|
|
|
}
|
2004-01-21 23:45:13 +00:00
|
|
|
|
exit (status);
|
1992-11-08 02:50:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2002-02-12 15:44:16 +00:00
|
|
|
|
/* Compute the next sequential output file name and store it into the
|
|
|
|
|
|
string `outfile'. */
|
1995-10-31 12:34:48 +00:00
|
|
|
|
|
|
|
|
|
|
static void
|
1995-10-31 12:36:43 +00:00
|
|
|
|
next_file_name (void)
|
1995-10-31 12:34:48 +00:00
|
|
|
|
{
|
2003-08-09 09:16:39 +00:00
|
|
|
|
/* Index in suffix_alphabet of each character in the suffix. */
|
|
|
|
|
|
static size_t *sufindex;
|
|
|
|
|
|
|
2002-02-12 15:44:16 +00:00
|
|
|
|
if (! outfile)
|
1998-01-18 11:18:08 +00:00
|
|
|
|
{
|
2002-02-12 15:44:16 +00:00
|
|
|
|
/* Allocate and initialize the first file name. */
|
|
|
|
|
|
|
|
|
|
|
|
size_t outbase_length = strlen (outbase);
|
|
|
|
|
|
size_t outfile_length = outbase_length + suffix_length;
|
|
|
|
|
|
if (outfile_length + 1 < outbase_length)
|
|
|
|
|
|
xalloc_die ();
|
|
|
|
|
|
outfile = xmalloc (outfile_length + 1);
|
|
|
|
|
|
outfile_mid = outfile + outbase_length;
|
|
|
|
|
|
memcpy (outfile, outbase, outbase_length);
|
2003-08-09 09:16:39 +00:00
|
|
|
|
memset (outfile_mid, suffix_alphabet[0], suffix_length);
|
2002-02-12 15:44:16 +00:00
|
|
|
|
outfile[outfile_length] = 0;
|
2003-11-04 06:25:45 +00:00
|
|
|
|
sufindex = xcalloc (suffix_length, sizeof *sufindex);
|
2002-02-12 15:44:16 +00:00
|
|
|
|
|
|
|
|
|
|
#if ! _POSIX_NO_TRUNC && HAVE_PATHCONF && defined _PC_NAME_MAX
|
|
|
|
|
|
/* POSIX requires that if the output file name is too long for
|
|
|
|
|
|
its directory, `split' must fail without creating any files.
|
|
|
|
|
|
This must be checked for explicitly on operating systems that
|
|
|
|
|
|
silently truncate file names. */
|
|
|
|
|
|
{
|
|
|
|
|
|
char *dir = dir_name (outfile);
|
|
|
|
|
|
long name_max = pathconf (dir, _PC_NAME_MAX);
|
2006-03-26 12:08:10 +00:00
|
|
|
|
if (0 <= name_max && name_max < base_len (last_component (outfile)))
|
2002-02-12 15:44:16 +00:00
|
|
|
|
error (EXIT_FAILURE, ENAMETOOLONG, "%s", outfile);
|
|
|
|
|
|
free (dir);
|
|
|
|
|
|
}
|
|
|
|
|
|
#endif
|
1998-01-18 11:18:08 +00:00
|
|
|
|
}
|
2002-02-12 15:44:16 +00:00
|
|
|
|
else
|
1995-10-31 12:34:48 +00:00
|
|
|
|
{
|
2002-02-12 15:44:16 +00:00
|
|
|
|
/* Increment the suffix in place, if possible. */
|
|
|
|
|
|
|
2003-08-09 09:16:39 +00:00
|
|
|
|
size_t i = suffix_length;
|
|
|
|
|
|
while (i-- != 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
sufindex[i]++;
|
|
|
|
|
|
outfile_mid[i] = suffix_alphabet[sufindex[i]];
|
|
|
|
|
|
if (outfile_mid[i])
|
|
|
|
|
|
return;
|
|
|
|
|
|
sufindex[i] = 0;
|
|
|
|
|
|
outfile_mid[i] = suffix_alphabet[sufindex[i]];
|
|
|
|
|
|
}
|
2008-04-04 11:13:13 -04:00
|
|
|
|
error (EXIT_FAILURE, 0, _("output file suffixes exhausted"));
|
1995-10-31 12:34:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Write BYTES bytes at BP to an output file.
|
2004-08-03 19:08:01 +00:00
|
|
|
|
If NEW_FILE_FLAG is true, open the next output file.
|
1995-10-31 12:34:48 +00:00
|
|
|
|
Otherwise add to the same output file already in use. */
|
|
|
|
|
|
|
|
|
|
|
|
static void
|
2004-08-03 19:08:01 +00:00
|
|
|
|
cwrite (bool new_file_flag, const char *bp, size_t bytes)
|
1995-10-31 12:34:48 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (new_file_flag)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (output_desc >= 0 && close (output_desc) < 0)
|
1996-03-24 16:59:11 +00:00
|
|
|
|
error (EXIT_FAILURE, errno, "%s", outfile);
|
1995-10-31 12:34:48 +00:00
|
|
|
|
|
|
|
|
|
|
next_file_name ();
|
1995-11-07 04:56:08 +00:00
|
|
|
|
if (verbose)
|
2008-02-06 08:25:24 +01:00
|
|
|
|
fprintf (stdout, _("creating file %s\n"), quote (outfile));
|
2005-07-03 07:20:33 +00:00
|
|
|
|
output_desc = open (outfile,
|
|
|
|
|
|
O_WRONLY | O_CREAT | O_TRUNC | O_BINARY,
|
|
|
|
|
|
(S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP
|
|
|
|
|
|
| S_IROTH | S_IWOTH));
|
1995-10-31 12:34:48 +00:00
|
|
|
|
if (output_desc < 0)
|
1996-03-24 16:59:11 +00:00
|
|
|
|
error (EXIT_FAILURE, errno, "%s", outfile);
|
1995-10-31 12:34:48 +00:00
|
|
|
|
}
|
2002-10-19 16:34:25 +00:00
|
|
|
|
if (full_write (output_desc, bp, bytes) != bytes)
|
1996-03-24 16:59:11 +00:00
|
|
|
|
error (EXIT_FAILURE, errno, "%s", outfile);
|
1995-10-31 12:34:48 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
2003-04-08 09:39:08 +00:00
|
|
|
|
/* Split into pieces of exactly N_BYTES bytes.
|
1992-11-08 02:50:43 +00:00
|
|
|
|
Use buffer BUF, whose size is BUFSIZE. */
|
|
|
|
|
|
|
1992-11-08 20:19:58 +00:00
|
|
|
|
static void
|
2003-04-09 14:37:47 +00:00
|
|
|
|
bytes_split (uintmax_t n_bytes, char *buf, size_t bufsize)
|
1992-11-08 02:50:43 +00:00
|
|
|
|
{
|
2002-10-19 16:34:25 +00:00
|
|
|
|
size_t n_read;
|
2004-08-03 19:08:01 +00:00
|
|
|
|
bool new_file_flag = true;
|
2002-10-19 16:34:25 +00:00
|
|
|
|
size_t to_read;
|
2003-04-09 14:37:47 +00:00
|
|
|
|
uintmax_t to_write = n_bytes;
|
1992-11-08 02:50:43 +00:00
|
|
|
|
char *bp_out;
|
|
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
2005-07-03 07:20:33 +00:00
|
|
|
|
n_read = full_read (STDIN_FILENO, buf, bufsize);
|
2002-10-19 16:34:25 +00:00
|
|
|
|
if (n_read == SAFE_READ_ERROR)
|
1996-03-24 16:59:11 +00:00
|
|
|
|
error (EXIT_FAILURE, errno, "%s", infile);
|
1992-11-08 02:50:43 +00:00
|
|
|
|
bp_out = buf;
|
|
|
|
|
|
to_read = n_read;
|
|
|
|
|
|
for (;;)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (to_read < to_write)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (to_read) /* do not write 0 bytes! */
|
|
|
|
|
|
{
|
|
|
|
|
|
cwrite (new_file_flag, bp_out, to_read);
|
|
|
|
|
|
to_write -= to_read;
|
2004-08-03 19:08:01 +00:00
|
|
|
|
new_file_flag = false;
|
1992-11-08 02:50:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2003-04-09 14:40:05 +00:00
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
size_t w = to_write;
|
|
|
|
|
|
cwrite (new_file_flag, bp_out, w);
|
|
|
|
|
|
bp_out += w;
|
|
|
|
|
|
to_read -= w;
|
2004-08-03 19:08:01 +00:00
|
|
|
|
new_file_flag = true;
|
2003-04-09 14:40:05 +00:00
|
|
|
|
to_write = n_bytes;
|
|
|
|
|
|
}
|
1992-11-08 02:50:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
while (n_read == bufsize);
|
|
|
|
|
|
}
|
1995-10-31 12:34:48 +00:00
|
|
|
|
|
2003-04-09 13:25:48 +00:00
|
|
|
|
/* Split into pieces of exactly N_LINES lines.
|
1992-11-08 02:50:43 +00:00
|
|
|
|
Use buffer BUF, whose size is BUFSIZE. */
|
|
|
|
|
|
|
1992-11-08 20:19:58 +00:00
|
|
|
|
static void
|
2003-04-09 14:37:47 +00:00
|
|
|
|
lines_split (uintmax_t n_lines, char *buf, size_t bufsize)
|
1992-11-08 02:50:43 +00:00
|
|
|
|
{
|
2002-10-19 16:34:25 +00:00
|
|
|
|
size_t n_read;
|
1992-11-08 02:50:43 +00:00
|
|
|
|
char *bp, *bp_out, *eob;
|
2004-08-03 19:08:01 +00:00
|
|
|
|
bool new_file_flag = true;
|
2003-04-09 14:37:47 +00:00
|
|
|
|
uintmax_t n = 0;
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
2005-07-03 07:20:33 +00:00
|
|
|
|
n_read = full_read (STDIN_FILENO, buf, bufsize);
|
2002-10-19 16:34:25 +00:00
|
|
|
|
if (n_read == SAFE_READ_ERROR)
|
1996-03-24 16:59:11 +00:00
|
|
|
|
error (EXIT_FAILURE, errno, "%s", infile);
|
1992-11-08 02:50:43 +00:00
|
|
|
|
bp = bp_out = buf;
|
|
|
|
|
|
eob = bp + n_read;
|
|
|
|
|
|
*eob = '\n';
|
|
|
|
|
|
for (;;)
|
|
|
|
|
|
{
|
2002-10-19 16:34:25 +00:00
|
|
|
|
bp = memchr (bp, '\n', eob - bp + 1);
|
|
|
|
|
|
if (bp == eob)
|
1992-11-08 02:50:43 +00:00
|
|
|
|
{
|
|
|
|
|
|
if (eob != bp_out) /* do not write 0 bytes! */
|
|
|
|
|
|
{
|
2002-10-19 16:34:25 +00:00
|
|
|
|
size_t len = eob - bp_out;
|
|
|
|
|
|
cwrite (new_file_flag, bp_out, len);
|
2004-08-03 19:08:01 +00:00
|
|
|
|
new_file_flag = false;
|
1992-11-08 02:50:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
2003-02-19 14:28:50 +00:00
|
|
|
|
|
|
|
|
|
|
++bp;
|
2003-04-09 13:25:48 +00:00
|
|
|
|
if (++n >= n_lines)
|
2003-02-19 14:28:50 +00:00
|
|
|
|
{
|
|
|
|
|
|
cwrite (new_file_flag, bp_out, bp - bp_out);
|
|
|
|
|
|
bp_out = bp;
|
2004-08-03 19:08:01 +00:00
|
|
|
|
new_file_flag = true;
|
2003-02-19 14:28:50 +00:00
|
|
|
|
n = 0;
|
|
|
|
|
|
}
|
1992-11-08 02:50:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
while (n_read == bufsize);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Split into pieces that are as large as possible while still not more
|
2003-04-08 09:39:08 +00:00
|
|
|
|
than N_BYTES bytes, and are split on line boundaries except
|
2003-04-09 14:37:47 +00:00
|
|
|
|
where lines longer than N_BYTES bytes occur.
|
2003-04-09 20:48:29 +00:00
|
|
|
|
FIXME: Allow N_BYTES to be any uintmax_t value, and don't require a
|
|
|
|
|
|
buffer of size N_BYTES, in case N_BYTES is very large. */
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
1992-11-08 20:19:58 +00:00
|
|
|
|
static void
|
2003-04-09 20:48:29 +00:00
|
|
|
|
line_bytes_split (size_t n_bytes)
|
1992-11-08 02:50:43 +00:00
|
|
|
|
{
|
2002-10-19 16:34:25 +00:00
|
|
|
|
size_t n_read;
|
1992-11-08 02:50:43 +00:00
|
|
|
|
char *bp;
|
2004-08-03 19:08:01 +00:00
|
|
|
|
bool eof = false;
|
2002-10-19 16:34:25 +00:00
|
|
|
|
size_t n_buffered = 0;
|
2003-04-11 10:51:56 +00:00
|
|
|
|
char *buf = xmalloc (n_bytes);
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
|
{
|
|
|
|
|
|
/* Fill up the full buffer size from the input file. */
|
|
|
|
|
|
|
2005-07-03 07:20:33 +00:00
|
|
|
|
n_read = full_read (STDIN_FILENO, buf + n_buffered, n_bytes - n_buffered);
|
2002-10-19 16:34:25 +00:00
|
|
|
|
if (n_read == SAFE_READ_ERROR)
|
1996-03-24 16:59:11 +00:00
|
|
|
|
error (EXIT_FAILURE, errno, "%s", infile);
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
|
|
|
|
|
n_buffered += n_read;
|
2003-04-08 09:30:09 +00:00
|
|
|
|
if (n_buffered != n_bytes)
|
2007-04-12 00:21:25 +02:00
|
|
|
|
{
|
|
|
|
|
|
if (n_buffered == 0)
|
|
|
|
|
|
break;
|
|
|
|
|
|
eof = true;
|
|
|
|
|
|
}
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
|
|
|
|
|
/* Find where to end this chunk. */
|
|
|
|
|
|
bp = buf + n_buffered;
|
2003-04-08 09:30:09 +00:00
|
|
|
|
if (n_buffered == n_bytes)
|
1992-11-08 02:50:43 +00:00
|
|
|
|
{
|
|
|
|
|
|
while (bp > buf && bp[-1] != '\n')
|
|
|
|
|
|
bp--;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* If chunk has no newlines, use all the chunk. */
|
|
|
|
|
|
if (bp == buf)
|
|
|
|
|
|
bp = buf + n_buffered;
|
|
|
|
|
|
|
|
|
|
|
|
/* Output the chars as one output file. */
|
2004-08-03 19:08:01 +00:00
|
|
|
|
cwrite (true, buf, bp - buf);
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
|
|
|
|
|
/* Discard the chars we just output; move rest of chunk
|
1995-01-28 13:06:29 +00:00
|
|
|
|
down to be the start of the next chunk. Source and
|
|
|
|
|
|
destination probably overlap. */
|
1992-11-08 02:50:43 +00:00
|
|
|
|
n_buffered -= bp - buf;
|
|
|
|
|
|
if (n_buffered > 0)
|
1995-01-28 13:06:29 +00:00
|
|
|
|
memmove (buf, bp, n_buffered);
|
1992-11-08 02:50:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
while (!eof);
|
|
|
|
|
|
free (buf);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2002-09-28 16:50:34 +00:00
|
|
|
|
#define FAIL_ONLY_ONE_WAY() \
|
|
|
|
|
|
do \
|
|
|
|
|
|
{ \
|
|
|
|
|
|
error (0, 0, _("cannot split in more than one way")); \
|
|
|
|
|
|
usage (EXIT_FAILURE); \
|
|
|
|
|
|
} \
|
|
|
|
|
|
while (0)
|
|
|
|
|
|
|
1996-03-21 22:41:04 +00:00
|
|
|
|
int
|
1995-10-31 12:36:43 +00:00
|
|
|
|
main (int argc, char **argv)
|
1992-11-08 02:50:43 +00:00
|
|
|
|
{
|
1995-10-31 12:34:48 +00:00
|
|
|
|
struct stat stat_buf;
|
|
|
|
|
|
enum
|
1992-11-08 02:50:43 +00:00
|
|
|
|
{
|
1995-10-31 12:34:48 +00:00
|
|
|
|
type_undef, type_bytes, type_byteslines, type_lines, type_digits
|
|
|
|
|
|
} split_type = type_undef;
|
2002-10-19 16:34:25 +00:00
|
|
|
|
size_t in_blk_size; /* optimal block size of input file device */
|
1995-10-31 12:34:48 +00:00
|
|
|
|
char *buf; /* file i/o buffer */
|
2004-04-15 09:10:54 +00:00
|
|
|
|
size_t page_size = getpagesize ();
|
2003-04-09 14:37:47 +00:00
|
|
|
|
uintmax_t n_units;
|
The following commands and options now support the standard size
suffixes kB, M, MB, G, GB, and so on for T, P, Y, Z, and Y:
head -c, head -n, od -j, od -N, od -S, split -b, split -C,
tail -c, tail -n.
* doc/coreutils.texi (od invocation, head invocation, tail invocation):
Document support for new size suffixes.
(head invocation, tail invocation):
Document that -n uses the same suffixes as -c.
(tail invocation): More-clearly document what leading "+" does.
* src/head.c (usage, string_to_integer): Support new suffixes.
* src/od.c (usage, main): Likewise.
* src/split.c (usage, main): Likewise.
* src/tail.c (usage, parse_options): Likewise.
Prompted by a patch from Evan Hunt.
2007-05-03 13:45:26 +02:00
|
|
|
|
static char const multipliers[] = "bEGKkMmPTYZ0";
|
1995-10-31 12:34:48 +00:00
|
|
|
|
int c;
|
|
|
|
|
|
int digits_optind = 0;
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
2003-06-17 18:13:23 +00:00
|
|
|
|
initialize_main (&argc, &argv);
|
2008-06-03 08:34:09 +02:00
|
|
|
|
set_program_name (argv[0]);
|
1996-03-09 20:19:13 +00:00
|
|
|
|
setlocale (LC_ALL, "");
|
|
|
|
|
|
bindtextdomain (PACKAGE, LOCALEDIR);
|
|
|
|
|
|
textdomain (PACKAGE);
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
2000-05-20 22:06:38 +00:00
|
|
|
|
atexit (close_stdout);
|
|
|
|
|
|
|
1995-10-31 12:34:48 +00:00
|
|
|
|
/* Parse command line options. */
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
1995-10-31 12:34:48 +00:00
|
|
|
|
infile = "-";
|
|
|
|
|
|
outbase = "x";
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
1995-10-31 12:34:48 +00:00
|
|
|
|
while (1)
|
1992-11-08 02:50:43 +00:00
|
|
|
|
{
|
1995-10-31 12:34:48 +00:00
|
|
|
|
/* This is the argv-index of the option we will read next. */
|
|
|
|
|
|
int this_optind = optind ? optind : 1;
|
|
|
|
|
|
|
2003-08-09 09:16:39 +00:00
|
|
|
|
c = getopt_long (argc, argv, "0123456789C:a:b:dl:", longopts, NULL);
|
Add more support for POSIX 1003.1-2001, which requires removal for
support of obsolete "-N" option syntax in expand, head, fold,
split, tail, unexpand, uniq, and which prohibits options with
optional arguments in od and pr.
(usage): Document this.
(main): Check for obsolete options.
(shortopts): New constant.
(main): Use -1, not EOF, for getopt_long.
2002-02-02 09:40:50 +00:00
|
|
|
|
if (c == -1)
|
1992-11-08 02:50:43 +00:00
|
|
|
|
break;
|
1995-10-31 12:34:48 +00:00
|
|
|
|
|
|
|
|
|
|
switch (c)
|
|
|
|
|
|
{
|
2002-02-12 15:44:16 +00:00
|
|
|
|
case 'a':
|
2002-09-28 16:50:34 +00:00
|
|
|
|
{
|
|
|
|
|
|
unsigned long tmp;
|
|
|
|
|
|
if (xstrtoul (optarg, NULL, 10, &tmp, "") != LONGINT_OK
|
2003-08-09 09:16:39 +00:00
|
|
|
|
|| SIZE_MAX / sizeof (size_t) < tmp)
|
2002-09-28 16:50:34 +00:00
|
|
|
|
{
|
|
|
|
|
|
error (0, 0, _("%s: invalid suffix length"), optarg);
|
|
|
|
|
|
usage (EXIT_FAILURE);
|
|
|
|
|
|
}
|
|
|
|
|
|
suffix_length = tmp;
|
|
|
|
|
|
}
|
2002-02-12 15:44:16 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
1995-10-31 12:34:48 +00:00
|
|
|
|
case 'b':
|
|
|
|
|
|
if (split_type != type_undef)
|
2002-09-28 16:50:34 +00:00
|
|
|
|
FAIL_ONLY_ONE_WAY ();
|
1995-10-31 12:34:48 +00:00
|
|
|
|
split_type = type_bytes;
|
The following commands and options now support the standard size
suffixes kB, M, MB, G, GB, and so on for T, P, Y, Z, and Y:
head -c, head -n, od -j, od -N, od -S, split -b, split -C,
tail -c, tail -n.
* doc/coreutils.texi (od invocation, head invocation, tail invocation):
Document support for new size suffixes.
(head invocation, tail invocation):
Document that -n uses the same suffixes as -c.
(tail invocation): More-clearly document what leading "+" does.
* src/head.c (usage, string_to_integer): Support new suffixes.
* src/od.c (usage, main): Likewise.
* src/split.c (usage, main): Likewise.
* src/tail.c (usage, parse_options): Likewise.
Prompted by a patch from Evan Hunt.
2007-05-03 13:45:26 +02:00
|
|
|
|
if (xstrtoumax (optarg, NULL, 10, &n_units, multipliers) != LONGINT_OK
|
2003-04-09 14:37:47 +00:00
|
|
|
|
|| n_units == 0)
|
1996-10-13 17:53:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
error (0, 0, _("%s: invalid number of bytes"), optarg);
|
|
|
|
|
|
usage (EXIT_FAILURE);
|
|
|
|
|
|
}
|
1995-10-31 12:34:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 'l':
|
|
|
|
|
|
if (split_type != type_undef)
|
2002-09-28 16:50:34 +00:00
|
|
|
|
FAIL_ONLY_ONE_WAY ();
|
1995-10-31 12:34:48 +00:00
|
|
|
|
split_type = type_lines;
|
2003-04-09 14:37:47 +00:00
|
|
|
|
if (xstrtoumax (optarg, NULL, 10, &n_units, "") != LONGINT_OK
|
|
|
|
|
|
|| n_units == 0)
|
1996-10-13 17:53:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
error (0, 0, _("%s: invalid number of lines"), optarg);
|
|
|
|
|
|
usage (EXIT_FAILURE);
|
|
|
|
|
|
}
|
1995-10-31 12:34:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case 'C':
|
|
|
|
|
|
if (split_type != type_undef)
|
2002-09-28 16:50:34 +00:00
|
|
|
|
FAIL_ONLY_ONE_WAY ();
|
1995-10-31 12:34:48 +00:00
|
|
|
|
split_type = type_byteslines;
|
The following commands and options now support the standard size
suffixes kB, M, MB, G, GB, and so on for T, P, Y, Z, and Y:
head -c, head -n, od -j, od -N, od -S, split -b, split -C,
tail -c, tail -n.
* doc/coreutils.texi (od invocation, head invocation, tail invocation):
Document support for new size suffixes.
(head invocation, tail invocation):
Document that -n uses the same suffixes as -c.
(tail invocation): More-clearly document what leading "+" does.
* src/head.c (usage, string_to_integer): Support new suffixes.
* src/od.c (usage, main): Likewise.
* src/split.c (usage, main): Likewise.
* src/tail.c (usage, parse_options): Likewise.
Prompted by a patch from Evan Hunt.
2007-05-03 13:45:26 +02:00
|
|
|
|
if (xstrtoumax (optarg, NULL, 10, &n_units, multipliers) != LONGINT_OK
|
2003-04-09 14:37:47 +00:00
|
|
|
|
|| n_units == 0 || SIZE_MAX < n_units)
|
1996-10-13 17:53:47 +00:00
|
|
|
|
{
|
|
|
|
|
|
error (0, 0, _("%s: invalid number of bytes"), optarg);
|
|
|
|
|
|
usage (EXIT_FAILURE);
|
|
|
|
|
|
}
|
1995-10-31 12:34:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case '0':
|
|
|
|
|
|
case '1':
|
|
|
|
|
|
case '2':
|
|
|
|
|
|
case '3':
|
|
|
|
|
|
case '4':
|
|
|
|
|
|
case '5':
|
|
|
|
|
|
case '6':
|
|
|
|
|
|
case '7':
|
|
|
|
|
|
case '8':
|
|
|
|
|
|
case '9':
|
2003-04-09 14:37:47 +00:00
|
|
|
|
if (split_type == type_undef)
|
|
|
|
|
|
{
|
|
|
|
|
|
split_type = type_digits;
|
|
|
|
|
|
n_units = 0;
|
|
|
|
|
|
}
|
1995-10-31 12:34:48 +00:00
|
|
|
|
if (split_type != type_undef && split_type != type_digits)
|
2002-09-28 16:50:34 +00:00
|
|
|
|
FAIL_ONLY_ONE_WAY ();
|
1995-10-31 12:34:48 +00:00
|
|
|
|
if (digits_optind != 0 && digits_optind != this_optind)
|
2003-04-08 09:50:50 +00:00
|
|
|
|
n_units = 0; /* More than one number given; ignore other. */
|
1995-10-31 12:34:48 +00:00
|
|
|
|
digits_optind = this_optind;
|
2005-07-05 06:32:54 +00:00
|
|
|
|
if (!DECIMAL_DIGIT_ACCUMULATE (n_units, c - '0', uintmax_t))
|
2003-04-09 20:48:29 +00:00
|
|
|
|
{
|
|
|
|
|
|
char buffer[INT_BUFSIZE_BOUND (uintmax_t)];
|
|
|
|
|
|
error (EXIT_FAILURE, 0,
|
|
|
|
|
|
_("line count option -%s%c... is too large"),
|
|
|
|
|
|
umaxtostr (n_units, buffer), c);
|
|
|
|
|
|
}
|
1995-10-31 12:34:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
2003-08-09 09:16:39 +00:00
|
|
|
|
case 'd':
|
|
|
|
|
|
suffix_alphabet = "0123456789";
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
2004-09-21 22:13:53 +00:00
|
|
|
|
case VERBOSE_OPTION:
|
|
|
|
|
|
verbose = true;
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
1999-04-04 15:44:26 +00:00
|
|
|
|
case_GETOPT_HELP_CHAR;
|
|
|
|
|
|
|
2003-10-18 10:05:47 +00:00
|
|
|
|
case_GETOPT_VERSION_CHAR (PROGRAM_NAME, AUTHORS);
|
1999-04-04 15:44:26 +00:00
|
|
|
|
|
1995-10-31 12:34:48 +00:00
|
|
|
|
default:
|
1996-10-13 17:53:47 +00:00
|
|
|
|
usage (EXIT_FAILURE);
|
1995-10-31 12:34:48 +00:00
|
|
|
|
}
|
1992-11-08 02:50:43 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
1995-10-31 12:34:48 +00:00
|
|
|
|
/* Handle default case. */
|
|
|
|
|
|
if (split_type == type_undef)
|
|
|
|
|
|
{
|
|
|
|
|
|
split_type = type_lines;
|
2003-04-08 09:50:50 +00:00
|
|
|
|
n_units = 1000;
|
1995-10-31 12:34:48 +00:00
|
|
|
|
}
|
1995-05-20 11:52:36 +00:00
|
|
|
|
|
2003-04-09 14:37:47 +00:00
|
|
|
|
if (n_units == 0)
|
1996-10-13 17:53:47 +00:00
|
|
|
|
{
|
2003-04-09 14:37:47 +00:00
|
|
|
|
error (0, 0, _("invalid number of lines: 0"));
|
1996-10-13 17:53:47 +00:00
|
|
|
|
usage (EXIT_FAILURE);
|
|
|
|
|
|
}
|
1995-05-20 11:52:36 +00:00
|
|
|
|
|
1995-10-31 12:34:48 +00:00
|
|
|
|
/* Get out the filename arguments. */
|
|
|
|
|
|
|
|
|
|
|
|
if (optind < argc)
|
|
|
|
|
|
infile = argv[optind++];
|
|
|
|
|
|
|
|
|
|
|
|
if (optind < argc)
|
|
|
|
|
|
outbase = argv[optind++];
|
|
|
|
|
|
|
|
|
|
|
|
if (optind < argc)
|
1996-10-13 17:53:47 +00:00
|
|
|
|
{
|
2004-06-21 15:03:35 +00:00
|
|
|
|
error (0, 0, _("extra operand %s"), quote (argv[optind]));
|
1996-10-13 17:53:47 +00:00
|
|
|
|
usage (EXIT_FAILURE);
|
|
|
|
|
|
}
|
1995-10-31 12:34:48 +00:00
|
|
|
|
|
|
|
|
|
|
/* Open the input file. */
|
2005-07-03 07:20:33 +00:00
|
|
|
|
if (! STREQ (infile, "-")
|
|
|
|
|
|
&& fd_reopen (STDIN_FILENO, infile, O_RDONLY, 0) < 0)
|
|
|
|
|
|
error (EXIT_FAILURE, errno, _("cannot open %s for reading"),
|
|
|
|
|
|
quote (infile));
|
|
|
|
|
|
|
1999-01-01 22:49:44 +00:00
|
|
|
|
/* Binary I/O is safer when bytecounts are used. */
|
2005-07-11 18:24:42 +00:00
|
|
|
|
if (O_BINARY && ! isatty (STDIN_FILENO))
|
|
|
|
|
|
freopen (NULL, "rb", stdin);
|
1992-11-08 02:50:43 +00:00
|
|
|
|
|
1995-10-31 12:34:48 +00:00
|
|
|
|
/* No output file is open now. */
|
|
|
|
|
|
output_desc = -1;
|
|
|
|
|
|
|
|
|
|
|
|
/* Get the optimal block size of input device and make a buffer. */
|
|
|
|
|
|
|
2005-07-03 07:20:33 +00:00
|
|
|
|
if (fstat (STDIN_FILENO, &stat_buf) != 0)
|
1996-03-24 16:59:11 +00:00
|
|
|
|
error (EXIT_FAILURE, errno, "%s", infile);
|
1995-10-31 12:34:48 +00:00
|
|
|
|
in_blk_size = ST_BLKSIZE (stat_buf);
|
|
|
|
|
|
|
2004-04-15 09:10:54 +00:00
|
|
|
|
buf = ptr_align (xmalloc (in_blk_size + 1 + page_size - 1), page_size);
|
1995-10-31 12:34:48 +00:00
|
|
|
|
|
|
|
|
|
|
switch (split_type)
|
|
|
|
|
|
{
|
|
|
|
|
|
case type_digits:
|
|
|
|
|
|
case type_lines:
|
2003-04-09 14:37:47 +00:00
|
|
|
|
lines_split (n_units, buf, in_blk_size);
|
1995-10-31 12:34:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case type_bytes:
|
2003-04-09 14:37:47 +00:00
|
|
|
|
bytes_split (n_units, buf, in_blk_size);
|
1995-10-31 12:34:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
case type_byteslines:
|
2003-04-09 14:37:47 +00:00
|
|
|
|
line_bytes_split (n_units);
|
1995-10-31 12:34:48 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
|
abort ();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2005-07-03 07:20:33 +00:00
|
|
|
|
if (close (STDIN_FILENO) != 0)
|
1996-03-24 16:59:11 +00:00
|
|
|
|
error (EXIT_FAILURE, errno, "%s", infile);
|
1995-10-31 12:34:48 +00:00
|
|
|
|
if (output_desc >= 0 && close (output_desc) < 0)
|
1996-03-24 16:59:11 +00:00
|
|
|
|
error (EXIT_FAILURE, errno, "%s", outfile);
|
1995-10-31 12:34:48 +00:00
|
|
|
|
|
1996-03-24 14:58:01 +00:00
|
|
|
|
exit (EXIT_SUCCESS);
|
1992-11-08 02:50:43 +00:00
|
|
|
|
}
|