]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
build: reflect gnulib changes to tempname
authorEric Blake <ebb9@byu.net>
Tue, 3 Nov 2009 15:51:31 +0000 (08:51 -0700)
committerEric Blake <ebb9@byu.net>
Thu, 5 Nov 2009 14:00:52 +0000 (07:00 -0700)
In glibc 2.11 and gnulib, gen_tempname added a parameter
suffixlen (unfortunately, it is typed as int rather than
size_t, for historical compatibility to a poor choice by BSD).

* gnulib: Import latest changes.
* gl/lib/tempname.h.diff: Accommodate new suffixlen parameter.
* gl/lib/tempname.c.diff (check_x_suffix): Allow for X in suffix
beyond x_suffix_len.
(gen_tempname_len): Add suffixlen parameter.
(__gen_tempname): Update caller.
* src/mktemp.c (mkstemp_len, mkdtemp_len): Update callers.

gl/lib/tempname.c.diff
gl/lib/tempname.h.diff
gnulib
src/mktemp.c

index 2b6c58fdc3d57d3b92a3370ae0a50e60f0fc0f92..8ffc5069295d45fea70a488f2ed75e3461a50e5a 100644 (file)
@@ -1,5 +1,5 @@
 diff --git c/lib/tempname.c i/lib/tempname.c
-index 4102134..a03346e 100644
+index 2da5afe..562955a 100644
 --- c/lib/tempname.c
 +++ i/lib/tempname.c
 @@ -22,6 +22,7 @@
@@ -10,45 +10,45 @@ index 4102134..a03346e 100644
  #endif
 
  #include <sys/types.h>
-@@ -45,6 +46,7 @@
- # define __GT_NOCREATE        3
+@@ -49,6 +50,7 @@
+ # error report this to bug-gnulib@gnu.org
  #endif
 
 +#include <stdbool.h>
  #include <stddef.h>
  #include <stdlib.h>
  #include <string.h>
-@@ -174,14 +176,20 @@ __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
+@@ -179,14 +181,21 @@ __path_search (char *tmpl, size_t tmpl_len, const char *dir, const char *pfx,
  }
  #endif /* _LIBC */
 
 +static inline bool
 +check_x_suffix (char const *s, size_t len)
 +{
-+  return strspn (s, "X") == len;
++  return len <= strspn (s, "X");
 +}
 +
  /* These are the characters used in temporary file names.  */
  static const char letters[] =
  "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
 
--/* Generate a temporary file name based on TMPL.  TMPL must match the
--   rules for mk[s]temp (i.e. end in "XXXXXX").  The name constructed
--   does not exist at the time of the call to __gen_tempname.  TMPL is
--   overwritten with the result.
-+/* Generate a temporary file name based on TMPL.  TMPL must end in a
-+   a sequence of at least X_SUFFIX_LEN "X"s.
-+   The name constructed does not exist at the time of the call to
+ /* Generate a temporary file name based on TMPL.  TMPL must match the
+-   rules for mk[s]temp (i.e. end in "XXXXXX", possibly with a suffix).
++   rules for mk[s]temp (i.e. end in at least X_SUFFIX_LEN "X"s,
++   possibly with a suffix).
+    The name constructed does not exist at the time of the call to
+-   __gen_tempname.  TMPL is overwritten with the result.
 +   this function.  TMPL is overwritten with the result.
 
     KIND may be one of:
     __GT_NOCREATE:     simply verify that the name does not exist
-@@ -192,23 +200,23 @@ static const char letters[] =
+@@ -197,23 +206,24 @@ static const char letters[] =
 
     We use a clever algorithm to get hard-to-predict names. */
  int
--__gen_tempname (char *tmpl, int flags, int kind)
-+gen_tempname_len (char *tmpl, int flags, int kind, size_t x_suffix_len)
+-__gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
++gen_tempname_len (char *tmpl, int suffixlen, int flags, int kind,
++                  size_t x_suffix_len)
  {
 -  int len;
 +  size_t len;
@@ -72,21 +72,22 @@ index 4102134..a03346e 100644
  #define ATTEMPTS_MIN (62 * 62 * 62)
 
    /* The number of times to attempt to generate a temporary file.  To
-@@ -220,43 +228,27 @@ __gen_tempname (char *tmpl, int flags, int kind)
+@@ -225,43 +235,28 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
  #endif
 
    len = strlen (tmpl);
--  if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
-+  if (len < x_suffix_len || ! check_x_suffix (&tmpl[len - x_suffix_len],
-+                                              x_suffix_len))
+-  if (len < 6 + suffixlen || memcmp (&tmpl[len - 6 - suffixlen], "XXXXXX", 6))
++  if (len < x_suffix_len + suffixlen
++      || ! check_x_suffix (&tmpl[len - x_suffix_len - suffixlen],
++                           x_suffix_len))
      {
        __set_errno (EINVAL);
        return -1;
      }
 
    /* This is where the Xs start.  */
--  XXXXXX = &tmpl[len - 6];
-+  XXXXXX = &tmpl[len - x_suffix_len];
+-  XXXXXX = &tmpl[len - 6 - suffixlen];
++  XXXXXX = &tmpl[len - x_suffix_len - suffixlen];
 
    /* Get some more or less random data.  */
 -#ifdef RANDOM_BITS
@@ -127,7 +128,7 @@ index 4102134..a03346e 100644
 
        switch (kind)
        {
-@@ -271,7 +263,7 @@ __gen_tempname (char *tmpl, int flags, int kind)
+@@ -276,7 +271,7 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
          break;
 
        case __GT_NOCREATE:
@@ -136,7 +137,7 @@ index 4102134..a03346e 100644
             succeeds if __xstat fails because the name does not exist.
             Note the continue to bypass the common logic at the bottom
             of the loop.  */
-@@ -280,11 +272,15 @@ __gen_tempname (char *tmpl, int flags, int kind)
+@@ -285,11 +280,15 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
              if (errno == ENOENT)
                {
                  __set_errno (save_errno);
@@ -155,7 +156,7 @@ index 4102134..a03346e 100644
            }
          continue;
 
-@@ -295,13 +291,32 @@ __gen_tempname (char *tmpl, int flags, int kind)
+@@ -301,13 +300,32 @@ __gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
        if (fd >= 0)
        {
          __set_errno (save_errno);
@@ -186,7 +187,7 @@ index 4102134..a03346e 100644
 +}
 +
 +int
-+__gen_tempname (char *tmpl, int flags, int kind)
++__gen_tempname (char *tmpl, int suffixlen, int flags, int kind)
 +{
-+  return gen_tempname_len (tmpl, flags, kind, 6);
++  return gen_tempname_len (tmpl, suffixlen, flags, kind, 6);
  }
index 5ceff5e8f6264ed94b4aaaac59b9709c1de2fb01..67074459a2b747a983a70b03a17bd464d9203db1 100644 (file)
@@ -1,12 +1,12 @@
 diff --git c/lib/tempname.h i/lib/tempname.h
-index edf7074..707edf4 100644
+index cd69e7d..9757db2 100644
 --- c/lib/tempname.h
 +++ i/lib/tempname.h
-@@ -34,4 +34,7 @@
-    GT_DIR:            create a directory, which will be mode 0700.
+@@ -46,5 +46,7 @@
 
     We use a clever algorithm to get hard-to-predict names. */
-+#include <stddef.h>
- extern int gen_tempname (char *tmpl, int flags, int kind);
-+extern int gen_tempname_len (char *tmpl, int flags, int kind,
+ extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind);
++extern int gen_tempname_len (char *tmpl, int suffixlen, int flags, int kind,
 +                             size_t x_suffix_len);
+
+ #endif /* GL_TEMPNAME_H */
diff --git a/gnulib b/gnulib
index 5ff811558adf7013f9fd9109fa794dd4e5ee8c91..757089b71ada13e18169e2be3509c1b07bd1c63d 160000 (submodule)
--- a/gnulib
+++ b/gnulib
@@ -1 +1 @@
-Subproject commit 5ff811558adf7013f9fd9109fa794dd4e5ee8c91
+Subproject commit 757089b71ada13e18169e2be3509c1b07bd1c63d
index e967d8eca8433c5970a9a8052bfba73d882a8f79..6cf40b0010ee8fc408ddaa1aee5bbaa14535be38 100644 (file)
@@ -110,13 +110,15 @@ count_trailing_X_s (const char *s)
 static int
 mkstemp_len (char *tmpl, size_t suff_len, bool dry_run)
 {
-  return gen_tempname_len (tmpl, 0, dry_run ? GT_NOCREATE : GT_FILE, suff_len);
+  return gen_tempname_len (tmpl, 0, 0, dry_run ? GT_NOCREATE : GT_FILE,
+                           suff_len);
 }
 
 static int
 mkdtemp_len (char *tmpl, size_t suff_len, bool dry_run)
 {
-  return gen_tempname_len (tmpl, 0, dry_run ? GT_NOCREATE : GT_DIR, suff_len);
+  return gen_tempname_len (tmpl, 0, 0, dry_run ? GT_NOCREATE : GT_DIR,
+                           suff_len);
 }
 
 int