mirror of
git://git.sv.gnu.org/coreutils.git
synced 2026-08-12 20:09:14 +02:00
(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.
This commit is contained in:
+22
-6
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user