[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: glibc sysdeps/posix/tempname.c artificially limited to TMP_MAX
From: |
Paul Eggert |
Subject: |
Re: glibc sysdeps/posix/tempname.c artificially limited to TMP_MAX |
Date: |
Mon, 26 Nov 2001 18:25:47 -0800 (PST) |
> From: Ulrich Drepper <address@hidden>
> Date: 26 Nov 2001 17:19:10 -0800
>
> This is the fault of the broken systems you are trying to support.
> The correct way to handle this is to fix these systems.
True in theory, but in practice it will take many years to fix old
systems like HP-UX or Solaris (or to retire them :-), and in the
meantime if it is easy to support them then GNU applications should do so.
> You cannot simply define a maximum values and be done. If this
> value is not at least as big as TMP_MAX you'll have to use TMP_MAX.
OK, here's a revised patch that always uses a number that is at least
as big as TMP_MAX. Please feel free to substitute some other
reasonable number for 62**6 in the definition of ATTEMPTS_MIN, if you
think 62**6 is too large.
2001-11-27 Paul Eggert <address@hidden>
* sysdeps/posix/tempname.c (__gen_tempname): Try at least
ATTEMPTS_MIN or TMP_MAX times, whichever is greater.
--- sysdeps/posix/tempname.c 2001/07/06 11:56:01 1.35
+++ sysdeps/posix/tempname.c 2001/11/27 02:20:50 1.35.0.3
@@ -231,10 +231,22 @@ __gen_tempname (char *tmpl, int kind)
char *XXXXXX;
static uint64_t value;
uint64_t random_time_bits;
- int count, fd = -1;
+ unsigned int count;
+ int fd = -1;
int save_errno = errno;
struct_stat64 st;
+ /* A lower bound on the number of temporary files to attempt to
+ generate. The maximum total number of temporary file names that
+ can exist for a given template is 62**6. Since unsigned int is
+ at least 32 bits wide, ATTEMPTS_MIN is always at least 965660736
+ even if some multiplications overflow; this is good enough. */
+ unsigned int attempts_min = (unsigned int) 62 * 62 * 62 * 62 * 62 * 62;
+
+ /* The number of times to attempt to generate a temporary file. To
+ conform to POSIX, this must be no smaller than TMP_MAX. */
+ unsigned int attempts = attempts_min < TMP_MAX ? TMP_MAX : attempts_min;
+
len = strlen (tmpl);
if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
{
@@ -261,7 +273,7 @@ __gen_tempname (char *tmpl, int kind)
#endif
value += random_time_bits ^ __getpid ();
- for (count = 0; count < TMP_MAX; value += 7777, ++count)
+ for (count = 0; count < attempts; value += 7777, ++count)
{
uint64_t v = value;