diff options
author | Jim Meyering <jim@meyering.net> | 1995-09-14 13:31:52 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1995-09-14 13:31:52 +0000 |
commit | b23b6bbcf776563e9d517fb307e923bb1d33fff7 (patch) | |
tree | 6934398f29ba1e983a3a6b11e00a855ba15f4388 /src | |
parent | 800e219a2d1d606f7e5ec649ddcbdb7327e98815 (diff) | |
download | coreutils-b23b6bbcf776563e9d517fb307e923bb1d33fff7.tar.xz |
(tempname): Replace `16' with a more readable expansion.
Make sure that SEQ never exceeds 99999.
Diffstat (limited to 'src')
-rw-r--r-- | src/sort.c | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/sort.c b/src/sort.c index d0ceb5947..89e7e8085 100644 --- a/src/sort.c +++ b/src/sort.c @@ -314,17 +314,23 @@ xfwrite (buf, size, nelem, fp) static char * tempname () { - static int seq; + static unsigned int seq; int len = strlen (temp_file_prefix); - char *name = xmalloc (len + 16); - struct tempnode *node = - (struct tempnode *) xmalloc (sizeof (struct tempnode)); + char *name = xmalloc (len + 1 + sizeof ("sort") - 1 + 5 + 5 + 1); + struct tempnode *node; + node = (struct tempnode *) xmalloc (sizeof (struct tempnode)); sprintf (name, "%s%ssort%5.5d%5.5d", temp_file_prefix, (len && temp_file_prefix[len - 1] != '/') ? "/" : "", - (unsigned int) getpid () & 0xffff, ++seq); + (unsigned int) getpid () & 0xffff, seq); + + /* Make sure that SEQ's value fits in 5 digits. */ + ++seq; + if (seq >= 100000) + seq = 0; + node->name = name; node->next = temphead.next; temphead.next = node; @@ -657,7 +663,8 @@ numcompare (a, b) { register int tmpa, tmpb, loga, logb, tmp; - tmpa = UCHAR (*a), tmpb = UCHAR (*b); + tmpa = UCHAR (*a); + tmpb = UCHAR (*b); while (blanks[tmpa]) tmpa = UCHAR (*++a); |