summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Haible <bruno@clisp.org>2009-08-23 14:11:27 +0200
committerBruno Haible <bruno@clisp.org>2009-08-23 14:11:27 +0200
commit0aa929caab127f13327b070132fff8a22d19bc75 (patch)
treead6c5fb09bbe513304b7d10786aa3fb0c488b9d1
parentd7834f34cb055a90437b1076b2c94bad34e317b8 (diff)
downloadgnulib-0aa929caab127f13327b070132fff8a22d19bc75.tar.gz
New module 'mkostemp'.
-rw-r--r--ChangeLog23
-rw-r--r--NEWS3
-rw-r--r--doc/glibc-functions/mkostemp.texi8
-rw-r--r--lib/mkdtemp.c4
-rw-r--r--lib/mkostemp.c45
-rw-r--r--lib/mkstemp.c4
-rw-r--r--lib/stdlib.in.h25
-rw-r--r--lib/tempname.c21
-rw-r--r--lib/tempname.h6
-rw-r--r--m4/mkostemp.m425
-rw-r--r--m4/stdlib_h.m44
-rw-r--r--modules/mkostemp27
-rw-r--r--modules/stdlib2
13 files changed, 170 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index ee8dd55cd9..77514a0a86 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,28 @@
2009-08-23 Bruno Haible <bruno@clisp.org>
+ New module 'mkostemp'.
+ Based on Ulrich Drepper's 2007-08-10 change in glibc.
+ * lib/stdlib.in.h (mksotemp): New declaration.
+ * lib/mkostemp.c: New file, from glibc with modifications.
+ * lib/tempname.h (GT_FILE): Remove outdated comment.
+ (gen_tempname): Add flags argument.
+ * lib/tempname.c (__GT_BIGFILE): Remove macro.
+ (__GT_FILE): Map to 1.
+ (small_open, large_open): Remove macros.
+ (__gen_tempname): Add flags argument. Remove code for __GT_BIGFILE.
+ * lib/mkstemp.c (mkstemp): Update.
+ * lib/mkdtemp.c (mkdtemp): Likewise.
+ * m4/mkostemp.m4: New file.
+ * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize GNULIB_MKOSTEMP,
+ HAVE_MKOSTEMP.
+ * modules/stdlib (Makefile.am): Substitute GNULIB_MKOSTEMP,
+ HAVE_MKOSTEMP.
+ * modules/mkostemp: New file, based on modules/mkstemp.
+ * doc/glibc-functions/mkostemp.texi: Mention the new module.
+ * NEWS: Mention the change.
+
+2009-08-23 Bruno Haible <bruno@clisp.org>
+
* lib/pipe2.c (pipe2): Support O_TEXT, O_BINARY on all platforms.
Reported by Eric Blake.
diff --git a/NEWS b/NEWS
index c4722c08ab..5b4d5180ef 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ User visible incompatible changes
Date Modules Changes
+2009-08-23 tempname The gen_tempname function takes an additional
+ 'flags' argument. You can safely pass 0.
+
2009-08-12 getopt This module is deprecated. Please choose among
getopt-posix and getopt-gnu. getopt-gnu provides
"long options" and "options with optional
diff --git a/doc/glibc-functions/mkostemp.texi b/doc/glibc-functions/mkostemp.texi
index d2776d5e9b..6acede758e 100644
--- a/doc/glibc-functions/mkostemp.texi
+++ b/doc/glibc-functions/mkostemp.texi
@@ -2,15 +2,15 @@
@subsection @code{mkostemp}
@findex mkostemp
-Gnulib module: ---
+Gnulib module: mkostemp
Portability problems fixed by Gnulib:
@itemize
+@item
+This function is missing on all non-glibc platforms:
+MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin, mingw, Interix 3.5, BeOS.
@end itemize
Portability problems not fixed by Gnulib:
@itemize
-@item
-This function is missing on all non-glibc platforms:
-MacOS X 10.3, FreeBSD 6.0, NetBSD 3.0, OpenBSD 3.8, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin, mingw, Interix 3.5, BeOS.
@end itemize
diff --git a/lib/mkdtemp.c b/lib/mkdtemp.c
index 6b9dd15134..b5181d155f 100644
--- a/lib/mkdtemp.c
+++ b/lib/mkdtemp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1999, 2001-2003, 2006-2007 Free Software Foundation, Inc.
+/* Copyright (C) 1999, 2001-2003, 2006-2007, 2009 Free Software Foundation, Inc.
This file is part of the GNU C Library.
This program is free software: you can redistribute it and/or modify
@@ -31,7 +31,7 @@
char *
mkdtemp (char *template)
{
- if (gen_tempname (template, GT_DIR))
+ if (gen_tempname (template, 0, GT_DIR))
return NULL;
else
return template;
diff --git a/lib/mkostemp.c b/lib/mkostemp.c
new file mode 100644
index 0000000000..6b94d409eb
--- /dev/null
+++ b/lib/mkostemp.c
@@ -0,0 +1,45 @@
+/* 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
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>. */
+
+#if !_LIBC
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+
+#if !_LIBC
+# include "tempname.h"
+# define __gen_tempname gen_tempname
+# define __GT_FILE GT_FILE
+#endif
+
+#include <stdio.h>
+
+#ifndef __GT_FILE
+# define __GT_FILE 0
+#endif
+
+/* Generate a unique temporary file name from TEMPLATE.
+ The last six characters of TEMPLATE must be "XXXXXX";
+ they are replaced with a string that makes the file name unique.
+ Then open the file and return a fd. */
+int
+mkostemp (template, flags)
+ char *template;
+ int flags;
+{
+ return __gen_tempname (template, flags, __GT_FILE);
+}
diff --git a/lib/mkstemp.c b/lib/mkstemp.c
index 1b052f9b7f..ccf7a7beed 100644
--- a/lib/mkstemp.c
+++ b/lib/mkstemp.c
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2001, 2005, 2006, 2007 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
@@ -40,5 +40,5 @@ int
mkstemp (template)
char *template;
{
- return __gen_tempname (template, __GT_FILE);
+ return __gen_tempname (template, 0, __GT_FILE);
}
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index c7c8e8fb7f..9ac7199568 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -207,6 +207,31 @@ extern char * mkdtemp (char * /*template*/);
#endif
+#if @GNULIB_MKOSTEMP@
+# if !@HAVE_MKOSTEMP@
+/* Create a unique temporary file from TEMPLATE.
+ The last six characters of TEMPLATE must be "XXXXXX";
+ they are replaced with a string that makes the file name unique.
+ The flags are a bitmask, possibly including O_CLOEXEC (defined in <fcntl.h>)
+ and O_TEXT, O_BINARY (defined in "binary-io.h").
+ The file is then created, with the specified flags, ensuring it didn't exist
+ before.
+ The file is created read-write (mask at least 0600 & ~umask), but it may be
+ world-readable and world-writable (mask 0666 & ~umask), depending on the
+ implementation.
+ Returns the open file descriptor if successful, otherwise -1 and errno
+ set. */
+extern int mkostemp (char * /*template*/, int /*flags*/);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mkostemp
+# define mkostemp(t,f) \
+ (GL_LINK_WARNING ("mkostemp is unportable - " \
+ "use gnulib module mkostemp for portability"), \
+ mkostemp (t, f))
+#endif
+
+
#if @GNULIB_MKSTEMP@
# if @REPLACE_MKSTEMP@
/* Create a unique temporary file from TEMPLATE.
diff --git a/lib/tempname.c b/lib/tempname.c
index 5a3a3260c4..410213447c 100644
--- a/lib/tempname.c
+++ b/lib/tempname.c
@@ -1,7 +1,7 @@
/* tempname.c - generate the name of a temporary file.
Copyright (C) 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
- 2000, 2001, 2002, 2003, 2005, 2006, 2007 Free Software Foundation,
+ 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009 Free Software Foundation,
Inc.
This program is free software: you can redistribute it and/or modify
@@ -40,8 +40,7 @@
# define TMP_MAX 238328
#endif
#ifndef __GT_FILE
-# define __GT_FILE 0
-# define __GT_BIGFILE 1
+# define __GT_FILE 1
# define __GT_DIR 2
# define __GT_NOCREATE 3
#endif
@@ -59,12 +58,9 @@
#if _LIBC
# define struct_stat64 struct stat64
-# define small_open __open
-# define large_open __open64
#else
# define struct_stat64 struct stat
-# define small_open open
-# define large_open open
+# define __open open
# define __gen_tempname gen_tempname
# define __getpid getpid
# define __gettimeofday gettimeofday
@@ -192,12 +188,11 @@ static const char letters[] =
at the time of the call.
__GT_FILE: create the file using open(O_CREAT|O_EXCL)
and return a read-write fd. The file is mode 0600.
- __GT_BIGFILE: same as __GT_FILE but use open64().
__GT_DIR: create a directory, which will be mode 0700.
We use a clever algorithm to get hard-to-predict names. */
int
-__gen_tempname (char *tmpl, int kind)
+__gen_tempname (char *tmpl, int flags, int kind)
{
int len;
char *XXXXXX;
@@ -266,11 +261,9 @@ __gen_tempname (char *tmpl, int kind)
switch (kind)
{
case __GT_FILE:
- fd = small_open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
- break;
-
- case __GT_BIGFILE:
- fd = large_open (tmpl, O_RDWR | O_CREAT | O_EXCL, S_IRUSR | S_IWUSR);
+ fd = __open (tmpl,
+ (flags & ~0777) | O_RDWR | O_CREAT | O_EXCL,
+ S_IRUSR | S_IWUSR);
break;
case __GT_DIR:
diff --git a/lib/tempname.h b/lib/tempname.h
index 74da03b3b2..edf7074310 100644
--- a/lib/tempname.h
+++ b/lib/tempname.h
@@ -1,6 +1,6 @@
/* Create a temporary file or directory.
- Copyright (C) 2006 Free Software Foundation, Inc.
+ Copyright (C) 2006, 2009 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -17,8 +17,6 @@
/* header written by Eric Blake */
-/* In gnulib, always prefer large files. GT_FILE maps to
- __GT_BIGFILE, not __GT_FILE, for a reason. */
#define GT_FILE 1
#define GT_DIR 2
#define GT_NOCREATE 3
@@ -36,4 +34,4 @@
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 kind);
+extern int gen_tempname (char *tmpl, int flags, int kind);
diff --git a/m4/mkostemp.m4 b/m4/mkostemp.m4
new file mode 100644
index 0000000000..6ec8fa04a9
--- /dev/null
+++ b/m4/mkostemp.m4
@@ -0,0 +1,25 @@
+# mkostemp.m4 serial 1
+dnl Copyright (C) 2009 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_FUNC_MKOSTEMP],
+[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+
+ dnl Persuade glibc <stdlib.h> to declare mkostemp().
+ AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+ AC_CHECK_FUNCS_ONCE([mkostemp])
+ if test $ac_cv_func_mkostemp != yes; then
+ HAVE_MKOSTEMP=0
+ AC_LIBOBJ([mkostemp])
+ gl_PREREQ_MKOSTEMP
+ fi
+])
+
+# Prerequisites of lib/mkostemp.c.
+AC_DEFUN([gl_PREREQ_MKOSTEMP],
+[
+])
diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4
index b295f16b27..89ac97fb92 100644
--- a/m4/stdlib_h.m4
+++ b/m4/stdlib_h.m4
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 15
+# stdlib_h.m4 serial 16
dnl Copyright (C) 2007-2009 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -40,6 +40,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
GNULIB_GETLOADAVG=0; AC_SUBST([GNULIB_GETLOADAVG])
GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT])
GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP])
+ GNULIB_MKOSTEMP=0; AC_SUBST([GNULIB_MKOSTEMP])
GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP])
GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV])
GNULIB_RANDOM_R=0; AC_SUBST([GNULIB_RANDOM_R])
@@ -55,6 +56,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT])
HAVE_MALLOC_POSIX=1; AC_SUBST([HAVE_MALLOC_POSIX])
HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP])
+ HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP])
HAVE_REALLOC_POSIX=1; AC_SUBST([HAVE_REALLOC_POSIX])
HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R])
HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH])
diff --git a/modules/mkostemp b/modules/mkostemp
new file mode 100644
index 0000000000..e336b90626
--- /dev/null
+++ b/modules/mkostemp
@@ -0,0 +1,27 @@
+Description:
+mkostemp() function: create a private temporary file, with specific opening
+flags.
+
+Files:
+lib/mkostemp.c
+m4/mkostemp.m4
+
+Depends-on:
+extensions
+stdlib
+tempname
+
+configure.ac:
+gl_FUNC_MKOSTEMP
+gl_STDLIB_MODULE_INDICATOR([mkostemp])
+
+Makefile.am:
+
+Include:
+<stdlib.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Jim Meyering, Bruno Haible
diff --git a/modules/stdlib b/modules/stdlib
index dea611f257..c19d7d68ec 100644
--- a/modules/stdlib
+++ b/modules/stdlib
@@ -34,6 +34,7 @@ stdlib.h: stdlib.in.h
-e 's|@''GNULIB_GETLOADAVG''@|$(GNULIB_GETLOADAVG)|g' \
-e 's|@''GNULIB_GETSUBOPT''@|$(GNULIB_GETSUBOPT)|g' \
-e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
+ -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \
-e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
-e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
-e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \
@@ -48,6 +49,7 @@ stdlib.h: stdlib.in.h
-e 's|@''HAVE_GETSUBOPT''@|$(HAVE_GETSUBOPT)|g' \
-e 's|@''HAVE_MALLOC_POSIX''@|$(HAVE_MALLOC_POSIX)|g' \
-e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \
+ -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \
-e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \
-e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
-e 's|@''HAVE_RPMATCH''@|$(HAVE_RPMATCH)|g' \