mkstemps, mkostemps: new modules
authorEric Blake <ebb9@byu.net>
Mon, 2 Nov 2009 22:33:10 +0000 (15:33 -0700)
committerEric Blake <ebb9@byu.net>
Thu, 5 Nov 2009 02:09:01 +0000 (19:09 -0700)
* modules/mkostemps: New module.
* modules/mkstemps: Likewise.
* lib/mkostemps.c (mkostemps): New file.
* lib/mkstemps.c (mkstemps): Likewise.
* m4/mkostemps.m4 (gl_FUNC_MKOSTEMPS): Likewise.
* m4/mkstemps.m4 (gl_FUNC_MKSTEMPS): Likewise.
* m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Add witnesses.
* modules/stdlib (Makefile.am): Substitute them.
* lib/stdlib.in.h (mkostemps, mkstemps): Declare them.
* doc/glibc-functions/mkstemps.texi (mkstemps): New file.
* doc/glibc-functions/mkostemps.texi (mkostemps): Likewise.
* doc/gnulib.texi (Glibc stdlib.h): Include them.
* MODULES.html.sh (File system functions): Mention them.

Signed-off-by: Eric Blake <ebb9@byu.net>
14 files changed:
ChangeLog
MODULES.html.sh
doc/glibc-functions/mkostemps.texi [new file with mode: 0644]
doc/glibc-functions/mkstemps.texi [new file with mode: 0644]
doc/gnulib.texi
lib/mkostemps.c [new file with mode: 0644]
lib/mkstemps.c [new file with mode: 0644]
lib/stdlib.in.h
m4/mkostemps.m4 [new file with mode: 0644]
m4/mkstemps.m4 [new file with mode: 0644]
m4/stdlib_h.m4
modules/mkostemps [new file with mode: 0644]
modules/mkstemps [new file with mode: 0644]
modules/stdlib

index e57ce69..34952e2 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2009-11-04  Eric Blake  <ebb9@byu.net>
 
+       mkstemps, mkostemps: new modules
+       * modules/mkostemps: New module.
+       * modules/mkstemps: Likewise.
+       * lib/mkostemps.c (mkostemps): New file.
+       * lib/mkstemps.c (mkstemps): Likewise.
+       * m4/mkostemps.m4 (gl_FUNC_MKOSTEMPS): Likewise.
+       * m4/mkstemps.m4 (gl_FUNC_MKSTEMPS): Likewise.
+       * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Add witnesses.
+       * modules/stdlib (Makefile.am): Substitute them.
+       * lib/stdlib.in.h (mkostemps, mkstemps): Declare them.
+       * doc/glibc-functions/mkstemps.texi (mkstemps): New file.
+       * doc/glibc-functions/mkostemps.texi (mkostemps): Likewise.
+       * doc/gnulib.texi (Glibc stdlib.h): Include them.
+       * MODULES.html.sh (File system functions): Mention them.
+
        tempname: resync from glibc
        * lib/tempname.c (__gen_tempname): Add suffixlen argument.  Use
        same values for __GT_FILE as glibc.  Abort even when assertions
index 2908890..23a3ddc 100755 (executable)
@@ -2480,6 +2480,9 @@ func_all_modules ()
   func_module mkancesdirs
   func_module mkfifoat
   func_module mkdir-p
+  func_module mkostemp
+  func_module mkostemps
+  func_module mkstemps
   func_module modechange
   func_module mountlist
   func_module openat
diff --git a/doc/glibc-functions/mkostemps.texi b/doc/glibc-functions/mkostemps.texi
new file mode 100644 (file)
index 0000000..eacb7f3
--- /dev/null
@@ -0,0 +1,16 @@
+@node mkostemps
+@subsection @code{mkostemps}
+@findex mkostemps
+
+Gnulib module: mkostemps
+
+Portability problems fixed by Gnulib:
+@itemize
+@item
+This function is missing on all non-glibc platforms:
+glibc 2.10, 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
+@end itemize
diff --git a/doc/glibc-functions/mkstemps.texi b/doc/glibc-functions/mkstemps.texi
new file mode 100644 (file)
index 0000000..a321a49
--- /dev/null
@@ -0,0 +1,17 @@
+@node mkstemps
+@subsection @code{mkstemps}
+@findex mkstemps
+
+Gnulib module: mkstemps
+
+Portability problems fixed by Gnulib:
+@itemize
+@item
+This function is missing on many non-glibc platforms:
+glibc 2.10, AIX 5.1, HP-UX 11, IRIX 6.5, OSF/1 5.1, Solaris 10, Cygwin
+1.5.x, mingw, Interix 3.5, BeOS.
+@end itemize
+
+Portability problems not fixed by Gnulib:
+@itemize
+@end itemize
index 8566eb3..3efbcb0 100644 (file)
@@ -5079,7 +5079,9 @@ This list of functions is sorted according to the header that declares them.
 * lcong48_r::
 * lrand48_r::
 * mkostemp::
+* mkostemps::
 * mrand48_r::
+* mkstemps::
 * nrand48_r::
 * on_exit::
 * ptsname_r::
@@ -5120,7 +5122,9 @@ This list of functions is sorted according to the header that declares them.
 @include glibc-functions/lcong48_r.texi
 @include glibc-functions/lrand48_r.texi
 @include glibc-functions/mkostemp.texi
+@include glibc-functions/mkostemps.texi
 @include glibc-functions/mrand48_r.texi
+@include glibc-functions/mkstemps.texi
 @include glibc-functions/nrand48_r.texi
 @include glibc-functions/on_exit.texi
 @include glibc-functions/ptsname_r.texi
diff --git a/lib/mkostemps.c b/lib/mkostemps.c
new file mode 100644 (file)
index 0000000..8de90fe
--- /dev/null
@@ -0,0 +1,57 @@
+/* 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 <errno.h>
+# include "tempname.h"
+# define __gen_tempname gen_tempname
+# ifndef __GT_FILE
+#  define __GT_FILE GT_FILE
+# endif
+# define __set_errno(x) errno = x;
+#endif
+
+#include <stdio.h>
+
+#ifndef __GT_FILE
+# define __GT_FILE 0
+#endif
+
+/* Generate a unique temporary file name from TEMPLATE.  The last six
+   characters before a suffix of length SUFFIXLEN of TEMPLATE must be
+   "XXXXXX"; they are replaced with a string that makes the filename
+   unique.  Then open the file and return a fd. */
+int
+mkostemps (template, suffixlen, flags)
+     char *template;
+     int suffixlen;
+     int flags;
+{
+  if (suffixlen < 0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  return __gen_tempname (template, suffixlen, flags, __GT_FILE);
+}
diff --git a/lib/mkstemps.c b/lib/mkstemps.c
new file mode 100644 (file)
index 0000000..5ce1697
--- /dev/null
@@ -0,0 +1,56 @@
+/* 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 <errno.h>
+# include "tempname.h"
+# define __gen_tempname gen_tempname
+# ifndef __GT_FILE
+#  define __GT_FILE GT_FILE
+# endif
+# define __set_errno(x) errno = x;
+#endif
+
+#include <stdio.h>
+
+#ifndef __GT_FILE
+# define __GT_FILE 0
+#endif
+
+/* Generate a unique temporary file name from TEMPLATE.  The last six
+   characters before a suffix of length SUFFIXLEN of TEMPLATE must be
+   "XXXXXX"; they are replaced with a string that makes the filename
+   unique.  Then open the file and return a fd. */
+int
+mkstemps (template, suffixlen)
+     char *template;
+     int suffixlen;
+{
+  if (suffixlen < 0)
+    {
+      __set_errno (EINVAL);
+      return -1;
+    }
+
+  return __gen_tempname (template, suffixlen, 0, __GT_FILE);
+}
index 7a9246a..e2c6bbf 100644 (file)
@@ -224,6 +224,31 @@ extern int mkostemp (char * /*template*/, int /*flags*/);
      mkostemp (t, f))
 #endif
 
+#if @GNULIB_MKOSTEMPS@
+# if !@HAVE_MKOSTEMPS@
+/* Create a unique temporary file from TEMPLATE.
+   The last six characters of TEMPLATE before a suffix of length
+   SUFFIXLEN 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 mkostemps (char * /*template*/, int /*suffixlen*/, int /*flags*/);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mkostemps
+# define mkostemps(t,s,f)                          \
+    (GL_LINK_WARNING ("mkostemps is unportable - " \
+                      "use gnulib module mkostemps for portability"), \
+     mkostemps (t, s, f))
+#endif
+
 #if @GNULIB_MKSTEMP@
 # if @REPLACE_MKSTEMP@
 /* Create a unique temporary file from TEMPLATE.
@@ -249,6 +274,28 @@ extern int mkstemp (char * /*template*/);
      mkstemp (t))
 #endif
 
+#if @GNULIB_MKSTEMPS@
+# if !@HAVE_MKSTEMPS@
+/* Create a unique temporary file from TEMPLATE.
+   The last six characters of TEMPLATE prior to a suffix of length
+   SUFFIXLEN must be "XXXXXX";
+   they are replaced with a string that makes the file name unique.
+   The file is then created, 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 mkstemps (char * /*template*/, int /*suffixlen*/);
+# endif
+#elif defined GNULIB_POSIXCHECK
+# undef mkstemps
+# define mkstemps(t,s)                             \
+    (GL_LINK_WARNING ("mkstemps is unportable - " \
+                      "use gnulib module mkstemps for portability"), \
+     mkstemps (t, s))
+#endif
+
 #if @GNULIB_PUTENV@
 # if @REPLACE_PUTENV@
 #  undef putenv
diff --git a/m4/mkostemps.m4 b/m4/mkostemps.m4
new file mode 100644 (file)
index 0000000..4327ec4
--- /dev/null
@@ -0,0 +1,19 @@
+# mkostemps.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_MKOSTEMPS],
+[
+  AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+
+  dnl Persuade glibc <stdlib.h> to declare mkostemps().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  AC_CHECK_FUNCS_ONCE([mkostemps])
+  if test $ac_cv_func_mkostemps != yes; then
+    HAVE_MKOSTEMPS=0
+    AC_LIBOBJ([mkostemps])
+  fi
+])
diff --git a/m4/mkstemps.m4 b/m4/mkstemps.m4
new file mode 100644 (file)
index 0000000..004bf8b
--- /dev/null
@@ -0,0 +1,19 @@
+# mkstemps.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_MKSTEMPS],
+[
+  AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+
+  dnl Persuade glibc <stdlib.h> to declare mkstemps().
+  AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+  AC_CHECK_FUNCS_ONCE([mkstemps])
+  if test $ac_cv_func_mkstemps != yes; then
+    HAVE_MKSTEMPS=0
+    AC_LIBOBJ([mkstemps])
+  fi
+])
index 42d551d..4556ac0 100644 (file)
@@ -1,4 +1,4 @@
-# stdlib_h.m4 serial 20
+# stdlib_h.m4 serial 21
 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,
@@ -41,7 +41,9 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   GNULIB_MALLOC_POSIX=0;  AC_SUBST([GNULIB_MALLOC_POSIX])
   GNULIB_MKDTEMP=0;       AC_SUBST([GNULIB_MKDTEMP])
   GNULIB_MKOSTEMP=0;      AC_SUBST([GNULIB_MKOSTEMP])
+  GNULIB_MKOSTEMPS=0;     AC_SUBST([GNULIB_MKOSTEMPS])
   GNULIB_MKSTEMP=0;       AC_SUBST([GNULIB_MKSTEMP])
+  GNULIB_MKSTEMPS=0;      AC_SUBST([GNULIB_MKSTEMPS])
   GNULIB_PUTENV=0;        AC_SUBST([GNULIB_PUTENV])
   GNULIB_RANDOM_R=0;      AC_SUBST([GNULIB_RANDOM_R])
   GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX])
@@ -61,6 +63,8 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS],
   HAVE_MALLOC_POSIX=1;       AC_SUBST([HAVE_MALLOC_POSIX])
   HAVE_MKDTEMP=1;            AC_SUBST([HAVE_MKDTEMP])
   HAVE_MKOSTEMP=1;           AC_SUBST([HAVE_MKOSTEMP])
+  HAVE_MKOSTEMPS=1;          AC_SUBST([HAVE_MKOSTEMPS])
+  HAVE_MKSTEMPS=1;           AC_SUBST([HAVE_MKSTEMPS])
   HAVE_RANDOM_R=1;           AC_SUBST([HAVE_RANDOM_R])
   HAVE_REALLOC_POSIX=1;      AC_SUBST([HAVE_REALLOC_POSIX])
   HAVE_REALPATH=1;           AC_SUBST([HAVE_REALPATH])
diff --git a/modules/mkostemps b/modules/mkostemps
new file mode 100644 (file)
index 0000000..54c55e6
--- /dev/null
@@ -0,0 +1,27 @@
+Description:
+mkostemps() function: create a private temporary file, with specific opening
+flags, and with suffix.
+
+Files:
+lib/mkostemps.c
+m4/mkostemps.m4
+
+Depends-on:
+extensions
+stdlib
+tempname
+
+configure.ac:
+gl_FUNC_MKOSTEMPS
+gl_STDLIB_MODULE_INDICATOR([mkostemps])
+
+Makefile.am:
+
+Include:
+<stdlib.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Eric Blake
diff --git a/modules/mkstemps b/modules/mkstemps
new file mode 100644 (file)
index 0000000..14f4698
--- /dev/null
@@ -0,0 +1,26 @@
+Description:
+mkstemps() function: create a private temporary file, with suffix
+
+Files:
+lib/mkstemps.c
+m4/mkstemps.m4
+
+Depends-on:
+extensions
+stdlib
+tempname
+
+configure.ac:
+gl_FUNC_MKSTEMPS
+gl_STDLIB_MODULE_INDICATOR([mkstemps])
+
+Makefile.am:
+
+Include:
+<stdlib.h>
+
+License:
+LGPLv2+
+
+Maintainer:
+Eric Blake
index 4968ce7..2e04088 100644 (file)
@@ -34,7 +34,9 @@ stdlib.h: stdlib.in.h
              -e 's|@''GNULIB_MALLOC_POSIX''@|$(GNULIB_MALLOC_POSIX)|g' \
              -e 's|@''GNULIB_MKDTEMP''@|$(GNULIB_MKDTEMP)|g' \
              -e 's|@''GNULIB_MKOSTEMP''@|$(GNULIB_MKOSTEMP)|g' \
+             -e 's|@''GNULIB_MKOSTEMPS''@|$(GNULIB_MKOSTEMPS)|g' \
              -e 's|@''GNULIB_MKSTEMP''@|$(GNULIB_MKSTEMP)|g' \
+             -e 's|@''GNULIB_MKSTEMPS''@|$(GNULIB_MKSTEMPS)|g' \
              -e 's|@''GNULIB_PUTENV''@|$(GNULIB_PUTENV)|g' \
              -e 's|@''GNULIB_RANDOM_R''@|$(GNULIB_RANDOM_R)|g' \
              -e 's|@''GNULIB_REALLOC_POSIX''@|$(GNULIB_REALLOC_POSIX)|g' \
@@ -53,6 +55,8 @@ stdlib.h: stdlib.in.h
              -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_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \
+             -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \
              -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \
              -e 's|@''HAVE_RANDOM_R''@|$(HAVE_RANDOM_R)|g' \
              -e 's|@''HAVE_REALLOC_POSIX''@|$(HAVE_REALLOC_POSIX)|g' \