diff options
author | Jim Meyering <jim@meyering.net> | 1999-01-01 22:51:58 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 1999-01-01 22:51:58 +0000 |
commit | b99ab6e97d4161a6653adfeda85d76e718efe64b (patch) | |
tree | 9b8cbe6aa3b82335c347608f7a11becec76e317f | |
parent | 13e5d174943e86143aa8b317ec84d6b3558c42c8 (diff) | |
download | coreutils-b99ab6e97d4161a6653adfeda85d76e718efe64b.tar.xz |
(PATH_MAX_IN_DIR) [HAVE_UNISTD_H]: New macro, for max
file name characters in a given directory.
(tempname): Make sure the temp file name is unique even if long
file names aren't supported.
-rw-r--r-- | src/sort.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/sort.c b/src/sort.c index d6ce76d9c..6e76059df 100644 --- a/src/sort.c +++ b/src/sort.c @@ -1,5 +1,5 @@ /* sort - sort lines of text (with all kinds of options). - Copyright (C) 88, 91-97, 98 Free Software Foundation, Inc. + Copyright (C) 88, 91-97, 98, 99 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,6 +37,12 @@ # include <langinfo.h> #endif +#if HAVE_UNISTD_H && defined(_PC_PATH_MAX) && _POSIX_NAME_MAX == 12 +# define PATH_MAX_IN_DIR(f) pathconf(f, _PC_PATH_MAX) +#else +# define PATH_MAX_IN_DIR(f) 255 +#endif + char *xstrdup (); /* Undefine, to avoid warning about redefinition on some systems. */ @@ -425,14 +431,24 @@ tempname (void) static unsigned int seq; int len = strlen (temp_file_prefix); char *name = xmalloc (len + 1 + sizeof ("sort") - 1 + 5 + 5 + 1); + int long_file_names = PATH_MAX_IN_DIR (temp_file_prefix) > 12; 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); + + /* If long filenames aren't supported, we cannot use filenames + longer than 8+3 and still assume they are unique. */ + if (long_file_names) + sprintf (name, + "%s%ssort%5.5d%5.5d", + temp_file_prefix, + (len && temp_file_prefix[len - 1] != '/') ? "/" : "", + (unsigned int) getpid () & 0xffff, seq); + else + sprintf (name, "%s%ss%5.5d%2.2d.%3.3d", + temp_file_prefix, + (len && temp_file_prefix[len - 1] != '/') ? "/" : "", + (unsigned int) getpid () & 0xffff, seq / 1000, seq % 1000); /* Make sure that SEQ's value fits in 5 digits. */ ++seq; |