summaryrefslogtreecommitdiff
path: root/src/split.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1998-01-18 11:18:08 +0000
committerJim Meyering <jim@meyering.net>1998-01-18 11:18:08 +0000
commitc1618a8c4c633c370142f3570e6e2054d9e4821a (patch)
tree4592417ebd71e042728db096af08c14219f7f2be /src/split.c
parent96be8bca9994db48d8a4388c14397cd9e1d7d033 (diff)
downloadcoreutils-c1618a8c4c633c370142f3570e6e2054d9e4821a.tar.xz
(next_file_name): Rewrite. This removes an artificial limit (albeit
already high, at INT_MAX :-) on the number of files split could create. Reported by Ralf W. Stephan.
Diffstat (limited to 'src/split.c')
-rw-r--r--src/split.c48
1 files changed, 19 insertions, 29 deletions
diff --git a/src/split.c b/src/split.c
index c82192138..2baa5794d 100644
--- a/src/split.c
+++ b/src/split.c
@@ -115,40 +115,30 @@ SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg.\n\
static void
next_file_name (void)
{
- int x;
- char *ne;
- unsigned int i;
+ static unsigned n_digits = 2;
+ char *p;
- static int first_call = 1;
+ /* Change any suffix of `z's to `a's. */
+ for (p = outfile_end - 1; *p == 'z'; p--)
+ {
+ *p = 'a';
+ }
- /* Status for outfile name generation. */
- static unsigned outfile_count = 0;
- static unsigned outfile_name_limit = 25 * 26;
- static unsigned outfile_name_generation = 1;
+ /* Increment the rightmost non-`z' character that was present before the
+ above z/a substitutions. There is guaranteed to be such a character. */
+ ++(*p);
- if (!first_call)
- outfile_count++;
- first_call = 0;
- if (outfile_count < outfile_name_limit)
+ /* If the result of that increment operation yielded a `z' and there
+ are only `z's to the left of it, then append two more `a' characters
+ to the end and add 1 (-1 + 2) to the number of digits (we're taking
+ out this `z' and adding two `a's). */
+ if (*p == 'z' && p == outfile_mid)
{
- for (ne = outfile_end - 1; ; ne--)
- {
- x = *ne;
- if (x != 'z')
- break;
- *ne = 'a';
- }
- *ne = x + 1;
- return;
+ ++n_digits;
+ ++outfile_mid;
+ *outfile_end++ = 'a';
+ *outfile_end++ = 'a';
}
-
- outfile_count = 0;
- outfile_name_limit *= 26;
- outfile_name_generation++;
- *outfile_mid++ = 'z';
- for (i = 0; i <= outfile_name_generation; i++)
- outfile_mid[i] = 'a';
- outfile_end += 2;
}
/* Write BYTES bytes at BP to an output file.