diff options
author | Eric Blake <ebb9@byu.net> | 2009-11-03 08:51:31 -0700 |
---|---|---|
committer | Eric Blake <ebb9@byu.net> | 2009-11-05 07:00:52 -0700 |
commit | d431c61873753673ad9fcbac90db6db04185e307 (patch) | |
tree | d567528063998de7dd5d5fac3abd30c88da8dfed /gl | |
parent | 5f29d118df9ad888f7c56de153966c16139c8f25 (diff) | |
download | coreutils-d431c61873753673ad9fcbac90db6db04185e307.tar.xz |
build: reflect gnulib changes to tempname
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.
Diffstat (limited to 'gl')
-rw-r--r-- | gl/lib/tempname.c.diff | 53 | ||||
-rw-r--r-- | gl/lib/tempname.h.diff | 12 |
2 files changed, 33 insertions, 32 deletions
diff --git a/gl/lib/tempname.c.diff b/gl/lib/tempname.c.diff index 2b6c58fdc..8ffc50692 100644 --- a/gl/lib/tempname.c.diff +++ b/gl/lib/tempname.c.diff @@ -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); } diff --git a/gl/lib/tempname.h.diff b/gl/lib/tempname.h.diff index 5ceff5e8f..67074459a 100644 --- a/gl/lib/tempname.h.diff +++ b/gl/lib/tempname.h.diff @@ -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 */ |