summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog12
-rw-r--r--NEWS3
-rw-r--r--lib/mkdtemp.c2
-rw-r--r--lib/mkostemp.c9
-rw-r--r--lib/mkstemp.c9
-rw-r--r--lib/tempname.c30
-rw-r--r--lib/tempname.h27
-rw-r--r--lib/tmpfile.c2
8 files changed, 67 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index 57a7fdb32b..e57ce69993 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
2009-11-04 Eric Blake <ebb9@byu.net>
+ tempname: resync from glibc
+ * lib/tempname.c (__gen_tempname): Add suffixlen argument. Use
+ same values for __GT_FILE as glibc. Abort even when assertions
+ are disabled.
+ * lib/tempname.h (GT_FILE): Use glibc __GT_FILE, if available, and
+ match its value otherwise. Allow idempotent inclusion.
+ * lib/mkdtemp.c (mkdtemp): Adjust caller.
+ * lib/mkostemp.c (mkostemp): Likewise.
+ * lib/mkstemp.c (mkstemp): Likewise.
+ * lib/tmpfile.c (tmpfile): Likewise.
+ * NEWS: Document this.
+
utimens: fix use of futimens on older Linux
* lib/utimens.c (fdutimens): Use updated, rather than original,
timespec to avoid bug in older Linux kernel.
diff --git a/NEWS b/NEWS
index fcf8fe550b..a6351504e4 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ User visible incompatible changes
Date Modules Changes
+2009-11-04 tempname The gen_tempname function takes an additional
+ 'suffixlen' argument. You can safely pass 0.
+
2009-11-04 nproc The num_processors function now takes an argument.
2009-11-02 inet_pton The use of this module now requires linking with
diff --git a/lib/mkdtemp.c b/lib/mkdtemp.c
index b5181d155f..7f07ee4fdf 100644
--- a/lib/mkdtemp.c
+++ b/lib/mkdtemp.c
@@ -31,7 +31,7 @@
char *
mkdtemp (char *template)
{
- if (gen_tempname (template, 0, GT_DIR))
+ if (gen_tempname (template, 0, 0, GT_DIR))
return NULL;
else
return template;
diff --git a/lib/mkostemp.c b/lib/mkostemp.c
index 6b94d409eb..02a97e6629 100644
--- a/lib/mkostemp.c
+++ b/lib/mkostemp.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1998, 1999, 2001, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2001, 2005, 2006, 2007, 2009 Free
+ Software Foundation, Inc.
This file is derived from the one in the GNU C Library.
This program is free software: you can redistribute it and/or modify
@@ -23,7 +24,9 @@
#if !_LIBC
# include "tempname.h"
# define __gen_tempname gen_tempname
-# define __GT_FILE GT_FILE
+# ifndef __GTFILE
+# define __GT_FILE GT_FILE
+# endif
#endif
#include <stdio.h>
@@ -41,5 +44,5 @@ mkostemp (template, flags)
char *template;
int flags;
{
- return __gen_tempname (template, flags, __GT_FILE);
+ return __gen_tempname (template, 0, flags, __GT_FILE);
}
diff --git a/lib/mkstemp.c b/lib/mkstemp.c
index ccf7a7beed..684c98331c 100644
--- a/lib/mkstemp.c
+++ b/lib/mkstemp.c
@@ -1,4 +1,5 @@
-/* Copyright (C) 1998, 1999, 2001, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
+/* Copyright (C) 1998, 1999, 2001, 2005, 2006, 2007, 2009 Free
+ Software Foundation, Inc.
This file is derived from the one in the GNU C Library.
This program is free software: you can redistribute it and/or modify
@@ -23,7 +24,9 @@
#if !_LIBC
# include "tempname.h"
# define __gen_tempname gen_tempname
-# define __GT_FILE GT_FILE
+# ifndef __GT_FILE
+# define __GT_FILE GT_FILE
+# endif
#endif
#include <stdio.h>
@@ -40,5 +43,5 @@ int
mkstemp (template)
char *template;
{
- return __gen_tempname (template, 0, __GT_FILE);
+ return __gen_tempname (template, 0, 0, __GT_FILE);
}
diff --git a/lib/tempname.c b/lib/tempname.c
index 410213447c..2da5afeecf 100644
--- a/lib/tempname.c
+++ b/lib/tempname.c
@@ -40,9 +40,13 @@
# define TMP_MAX 238328
#endif
#ifndef __GT_FILE
-# define __GT_FILE 1
-# define __GT_DIR 2
-# define __GT_NOCREATE 3
+# define __GT_FILE 0
+# define __GT_DIR 1
+# define __GT_NOCREATE 2
+#endif
+#if !_LIBC && (GT_FILE != __GT_FILE || GT_DIR != __GT_DIR \
+ || GT_NOCREATE != __GT_NOCREATE)
+# error report this to bug-gnulib@gnu.org
#endif
#include <stddef.h>
@@ -60,11 +64,12 @@
# define struct_stat64 struct stat64
#else
# define struct_stat64 struct stat
-# define __open open
# define __gen_tempname gen_tempname
# define __getpid getpid
# define __gettimeofday gettimeofday
# define __mkdir mkdir
+# define __open open
+# define __open64 open
# define __lxstat64(version, file, buf) lstat (file, buf)
# define __xstat64(version, file, buf) stat (file, buf)
#endif
@@ -179,9 +184,9 @@ 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.
+ rules for mk[s]temp (i.e. end in "XXXXXX", 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.
KIND may be one of:
__GT_NOCREATE: simply verify that the name does not exist
@@ -192,7 +197,7 @@ 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 (char *tmpl, int suffixlen, int flags, int kind)
{
int len;
char *XXXXXX;
@@ -220,14 +225,14 @@ __gen_tempname (char *tmpl, int flags, int kind)
#endif
len = strlen (tmpl);
- if (len < 6 || strcmp (&tmpl[len - 6], "XXXXXX"))
+ if (len < 6 + suffixlen || memcmp (&tmpl[len - 6 - suffixlen], "XXXXXX", 6))
{
__set_errno (EINVAL);
return -1;
}
/* This is where the Xs start. */
- XXXXXX = &tmpl[len - 6];
+ XXXXXX = &tmpl[len - 6 - suffixlen];
/* Get some more or less random data. */
#ifdef RANDOM_BITS
@@ -262,8 +267,8 @@ __gen_tempname (char *tmpl, int flags, int kind)
{
case __GT_FILE:
fd = __open (tmpl,
- (flags & ~0777) | O_RDWR | O_CREAT | O_EXCL,
- S_IRUSR | S_IWUSR);
+ (flags & ~O_ACCMODE)
+ | O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
break;
case __GT_DIR:
@@ -290,6 +295,7 @@ __gen_tempname (char *tmpl, int flags, int kind)
default:
assert (! "invalid KIND in __gen_tempname");
+ abort ();
}
if (fd >= 0)
diff --git a/lib/tempname.h b/lib/tempname.h
index edf7074310..cd69e7d755 100644
--- a/lib/tempname.h
+++ b/lib/tempname.h
@@ -17,14 +17,25 @@
/* header written by Eric Blake */
-#define GT_FILE 1
-#define GT_DIR 2
-#define GT_NOCREATE 3
+#ifndef GL_TEMPNAME_H
+# define GL_TEMPNAME_H
+
+# include <stdio.h>
+
+# ifdef __GT_FILE
+# define GT_FILE __GT_FILE
+# define GT_DIR __GT_DIR
+# define GT_NOCREATE __GT_NOCREATE
+# else
+# define GT_FILE 0
+# define GT_DIR 1
+# define GT_NOCREATE 2
+# endif
/* 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.
+ rules for mk[s]temp (i.e. end in "XXXXXX", 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.
KIND may be one of:
GT_NOCREATE: simply verify that the name does not exist
@@ -34,4 +45,6 @@
GT_DIR: create a directory, which will be mode 0700.
We use a clever algorithm to get hard-to-predict names. */
-extern int gen_tempname (char *tmpl, int flags, int kind);
+extern int gen_tempname (char *tmpl, int suffixlen, int flags, int kind);
+
+#endif /* GL_TEMPNAME_H */
diff --git a/lib/tmpfile.c b/lib/tmpfile.c
index 19c8a5e243..83df9fe296 100644
--- a/lib/tmpfile.c
+++ b/lib/tmpfile.c
@@ -83,7 +83,7 @@ tmpfile (void)
do
{
memcpy (&xtemplate[len - 6], "XXXXXX", 6);
- if (gen_tempname (xtemplate, 0, GT_NOCREATE) < 0)
+ if (gen_tempname (xtemplate, 0, 0, GT_NOCREATE) < 0)
{
fd = -1;
break;