Mirror of git://git.busybox.net/busybox with our patches on top
Source
xxxxxxxxxx
/* vi: set sw=4 ts=4: */
/*
* split - split a file into pieces
* Copyright (c) 2007 Bernhard Reutner-Fischer
*
* Licensed under GPLv2 or later, see file LICENSE in this source tree.
*/
/* BB_AUDIT: SUSv3 compliant
* SUSv3 requirements:
* http://www.opengroup.org/onlinepubs/009695399/utilities/split.html
*/
//usage:#define split_trivial_usage
//usage: "[OPTIONS] [INPUT [PREFIX]]"
//usage:#define split_full_usage "\n\n"
//usage: " -b N[k|m] Split by N (kilo|mega)bytes"
//usage: "\n -l N Split by N lines"
//usage: "\n -a N Use N letters as suffix"
//usage:
//usage:#define split_example_usage
//usage: "$ split TODO foo\n"
//usage: "$ cat TODO | split -a 2 -l 2 TODO_\n"
static const struct suffix_mult split_suffixes[] = {
{ "b", 512 },
{ "k", 1024 },
{ "m", 1024*1024 },
{ "g", 1024*1024*1024 },
{ "", 0 }
};
/* Increment the suffix part of the filename.
* Returns NULL if we are out of filenames.
*/
static char *next_file(char *old, unsigned suffix_len)
{
size_t end = strlen(old);
unsigned i = 1;
char *curr;
while (1) {
curr = old + end - i;
if (*curr < 'z') {
*curr += 1;
break;
}
i++;
if (i > suffix_len) {
return NULL;
}
*curr = 'a';
}
return old;
}
enum { READ_BUFFER_SIZE = COMMON_BUFSIZE - 1 };