bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

glibc sysdeps/posix/tempname.c artificially limited to TMP_MAX


From: Paul Eggert
Subject: glibc sysdeps/posix/tempname.c artificially limited to TMP_MAX
Date: Sun, 18 Nov 2001 15:55:59 -0800 (PST)

This problem was discovered by a GNU textutils user on HP-UX 10.20.
It turns out that its mkstemp breaks after allocating 26 files, which
broke GNU 'sort'.

Part of the fix is to have GNU textutils substitute its own mkstemp (a
copy of glibc's) for HP-UX's.  However, this runs into a related
problem: HP-UX defines TMP_MAX to be 17576, and when compiled as user
code glibc mkstemp refuses to allocate more than 17576 temporary
files.  This number is uncomfortably small for GNU 'sort', as it
allocates lots of temporaries.

So, to finish the fix, I'd like to remove this artificial limitation
of glibc.  Looking at the code, there's no reason for tempname.c to
inspect TMP_MAX.  TMP_MAX is merely a minimum; the code is free to go
beyond TMP_MAX.

Once this patch is installed, you can increase glibc's TMP_MAX to the
minimum of INT_MAX and 62**6; but this can be done independently, and
increasing glibc's TMP_MAX isn't needed to fix this HP-UX problem.

Here is a proposed patch.

2001-11-18  Paul Eggert  <address@hidden>

        * sysdeps/posix/tempname.c (TMP_MAX): Remove; no longer needed.
        (TEMPORARIES): New macro.
        (__gen_tempname): Use TEMPORARIES rather than TMP_MAX.  This
        removes an artificial limitation (e.g. HP-UX 10.20, where
        TMP_MAX is 17576).

===================================================================
RCS file: tempname.c,v
retrieving revision 1.35
retrieving revision 1.35.0.1
diff -pu -r1.35 -r1.35.0.1
--- sysdeps/posix/tempname.c    2001/07/06 11:56:01     1.35
+++ sysdeps/posix/tempname.c    2001/11/18 22:57:22     1.35.0.1
@@ -32,9 +32,6 @@
 #ifndef P_tmpdir
 # define P_tmpdir "/tmp"
 #endif
-#ifndef TMP_MAX
-# define TMP_MAX 238328
-#endif
 #ifndef __GT_FILE
 # define __GT_FILE     0
 # define __GT_BIGFILE  1
@@ -135,6 +132,11 @@
 # define uint64_t uintmax_t
 #endif
 
+/* The total number of temporary file names that can exist for a given
+   template is 62**6.  On ancient hosts where uint64_t is really 32
+   bits, TEMPORARIES evaluates to 965660736, which is good enough.  */
+#define TEMPORARIES ((uint64_t) 62 * 62 * 62 * 62 * 62 * 62)
+
 /* Return nonzero if DIR is an existent directory.  */
 static int
 direxists (const char *dir)
@@ -231,7 +233,8 @@ __gen_tempname (char *tmpl, int kind)
   char *XXXXXX;
   static uint64_t value;
   uint64_t random_time_bits;
-  int count, fd = -1;
+  uint64_t count;
+  int fd = -1;
   int save_errno = errno;
   struct_stat64 st;
 
@@ -261,7 +264,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 < TEMPORARIES; value += 7777, ++count)
     {
       uint64_t v = value;
 



reply via email to

[Prev in Thread] Current Thread [Next in Thread]