diff options
-rw-r--r-- | src/sort.c | 22 |
1 files changed, 9 insertions, 13 deletions
diff --git a/src/sort.c b/src/sort.c index 5918b6a6f..a0fb854c2 100644 --- a/src/sort.c +++ b/src/sort.c @@ -439,8 +439,6 @@ tempname (void) int long_file_names = NAME_MAX_IN_DIR (temp_dir) > 12; struct tempnode *node; - node = (struct tempnode *) xmalloc (sizeof (struct tempnode)); - /* If long filenames aren't supported, we cannot use filenames longer than 8+3 and still assume they are unique. */ if (long_file_names) @@ -450,21 +448,19 @@ tempname (void) (len && temp_dir[len - 1] != '/') ? "/" : "", (unsigned int) getpid () & 0xffff, seq); else - { - sprintf (name, "%s%ss%5.5d%2.2d.%3.3d", - temp_dir, - (len && temp_dir[len - 1] != '/') ? "/" : "", - (unsigned int) getpid () & 0xffff, seq / 1000, seq % 1000); - - /* FIXME: fail if seq exceeds 99999 -- at which point sort - would start reusing temporary file names. */ - } + sprintf (name, "%s%ss%5.5d%2.2d.%3.3d", + temp_dir, + (len && temp_dir[len - 1] != '/') ? "/" : "", + (unsigned int) getpid () & 0xffff, seq / 1000, seq % 1000); - /* Make sure that SEQ's value fits in 5 digits. */ ++seq; - if (seq >= 100000) + + /* Make sure that SEQ's value fits in 5 digits if temp_dir is on + an 8.3 filesystem. */ + if (!long_file_names && seq >= 100000) seq = 0; + node = (struct tempnode *) xmalloc (sizeof (struct tempnode)); node->name = name; node->next = temphead.next; temphead.next = node; |