From: Jim Meyering Date: Sun, 18 Jan 1998 11:18:08 +0000 (+0000) Subject: (next_file_name): Rewrite. This removes an artificial limit (albeit X-Git-Tag: FILEUTILS-3_16l~66 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c1618a8c4c633c370142f3570e6e2054d9e4821a;p=platform%2Fupstream%2Fcoreutils.git (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. --- diff --git a/src/split.c b/src/split.c index c821921..2baa579 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.