bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

mkostemps


From: Eric Blake
Subject: mkostemps
Date: Mon, 2 Nov 2009 23:18:06 +0000 (UTC)
User-agent: Loom/3.14 (http://gmane.org/)

Now that glibc 2.11 offers mkostemps, we should too.  Any objections to this 
patch series?

Eric Blake (3):
      tempname: resync from glibc
This patch conflicts with coreutils' local override of tempname.c, so I'm also 
working on a coreutils followup patch to fix things once coreutils imports the 
latest gnulib, as well as to make mktemp(1) smarter.

      mkstemps, mkostemps: new modules
Pretty much straight out of glibc.

      stdlib-safer: wrap all mkstemp variants
Makes "stdlib--.h" recognize the 2 new variants, as well as mkostemp.


>From 75660128d203fbbcc985635f8fd49ca25bc72fe7 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 2 Nov 2009 13:19:27 -0700
Subject: [PATCH 1/3] 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.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog      |   12 ++++++++++++
 NEWS           |    3 +++
 lib/mkdtemp.c  |    2 +-
 lib/mkostemp.c |    2 +-
 lib/mkstemp.c  |    2 +-
 lib/tempname.c |   30 ++++++++++++++++++------------
 lib/tempname.h |   27 ++++++++++++++++++++-------
 lib/tmpfile.c  |    2 +-
 8 files changed, 57 insertions(+), 23 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 786a46c..8103f83 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,17 @@
 2009-11-02  Eric Blake  <address@hidden>

+       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.
+
        mktime, timegm: share common declaration
        * lib/mktime-internal.h: New file.
        * lib/mktime.c: Use it rather than open-coding a declaration.
diff --git a/NEWS b/NEWS
index 5ae0d78..7a12584 100644
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,9 @@ User visible incompatible changes

 Date        Modules         Changes

+2009-11-02  tempname        The gen_tempname function takes an additional
+                            'suffixlen' argument. You can safely pass 0.
+
 2009-10-10  utimens         The use of this module now requires linking with
                             $(LIB_CLOCK_GETTIME).

diff --git a/lib/mkdtemp.c b/lib/mkdtemp.c
index b5181d1..7f07ee4 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 6b94d40..f8c1acb 100644
--- a/lib/mkostemp.c
+++ b/lib/mkostemp.c
@@ -41,5 +41,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 ccf7a7b..0e19251 100644
--- a/lib/mkstemp.c
+++ b/lib/mkstemp.c
@@ -40,5 +40,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 4102134..2da5afe 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 address@hidden
 #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 edf7074..6417df2 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 19c8a5e..83df9fe 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;
-- 
1.6.4.2


>From 358190b19b81c6f3b51604b6156421fd96c27554 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 2 Nov 2009 15:33:10 -0700
Subject: [PATCH 2/3] 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.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog                          |   15 ++++++++++
 MODULES.html.sh                    |    3 ++
 doc/glibc-functions/mkostemps.texi |   16 ++++++++++
 doc/glibc-functions/mkstemps.texi  |   17 +++++++++++
 doc/gnulib.texi                    |    4 ++
 lib/mkostemps.c                    |   55 ++++++++++++++++++++++++++++++++++++
 lib/mkstemps.c                     |   53 ++++++++++++++++++++++++++++++++++
 lib/stdlib.in.h                    |   47 ++++++++++++++++++++++++++++++
 m4/mkostemps.m4                    |   19 ++++++++++++
 m4/mkstemps.m4                     |   19 ++++++++++++
 m4/stdlib_h.m4                     |    6 +++-
 modules/mkostemps                  |   27 +++++++++++++++++
 modules/mkstemps                   |   26 +++++++++++++++++
 modules/stdlib                     |    4 ++
 14 files changed, 310 insertions(+), 1 deletions(-)
 create mode 100644 doc/glibc-functions/mkostemps.texi
 create mode 100644 doc/glibc-functions/mkstemps.texi
 create mode 100644 lib/mkostemps.c
 create mode 100644 lib/mkstemps.c
 create mode 100644 m4/mkostemps.m4
 create mode 100644 m4/mkstemps.m4
 create mode 100644 modules/mkostemps
 create mode 100644 modules/mkstemps

diff --git a/ChangeLog b/ChangeLog
index 8103f83..4d9704c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,20 @@
 2009-11-02  Eric Blake  <address@hidden>

+       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
diff --git a/MODULES.html.sh b/MODULES.html.sh
index 2908890..23a3ddc 100755
--- a/MODULES.html.sh
+++ b/MODULES.html.sh
@@ -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
index 0000000..eacb7f3
--- /dev/null
+++ b/doc/glibc-functions/mkostemps.texi
@@ -0,0 +1,16 @@
address@hidden mkostemps
address@hidden @code{mkostemps}
address@hidden mkostemps
+
+Gnulib module: mkostemps
+
+Portability problems fixed by Gnulib:
address@hidden
address@hidden
+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.
address@hidden itemize
+
+Portability problems not fixed by Gnulib:
address@hidden
address@hidden itemize
diff --git a/doc/glibc-functions/mkstemps.texi b/doc/glibc-
functions/mkstemps.texi
new file mode 100644
index 0000000..a321a49
--- /dev/null
+++ b/doc/glibc-functions/mkstemps.texi
@@ -0,0 +1,17 @@
address@hidden mkstemps
address@hidden @code{mkstemps}
address@hidden mkstemps
+
+Gnulib module: mkstemps
+
+Portability problems fixed by Gnulib:
address@hidden
address@hidden
+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.
address@hidden itemize
+
+Portability problems not fixed by Gnulib:
address@hidden
address@hidden itemize
diff --git a/doc/gnulib.texi b/doc/gnulib.texi
index 8566eb3..3efbcb0 100644
--- a/doc/gnulib.texi
+++ b/doc/gnulib.texi
@@ -5079,7 +5079,9 @@ Glibc stdlib.h
 * lcong48_r::
 * lrand48_r::
 * mkostemp::
+* mkostemps::
 * mrand48_r::
+* mkstemps::
 * nrand48_r::
 * on_exit::
 * ptsname_r::
@@ -5120,7 +5122,9 @@ Glibc stdlib.h
 @include glibc-functions/lcong48_r.texi
 @include glibc-functions/lrand48_r.texi
 @include glibc-functions/mkostemp.texi
address@hidden glibc-functions/mkostemps.texi
 @include glibc-functions/mrand48_r.texi
address@hidden 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
index 0000000..f43d3d5
--- /dev/null
+++ b/lib/mkostemps.c
@@ -0,0 +1,55 @@
+/* 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
+# define __GT_FILE GT_FILE
+# 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
index 0000000..d74de6a
--- /dev/null
+++ b/lib/mkstemps.c
@@ -0,0 +1,53 @@
+/* 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
+# define __GT_FILE GT_FILE
+# 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);
+}
diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h
index 7a9246a..e2c6bbf 100644
--- a/lib/stdlib.in.h
+++ b/lib/stdlib.in.h
@@ -224,6 +224,31 @@ extern int mkostemp (char * /*template*/, int /*flags*/);
      mkostemp (t, f))
 #endif

+#if @GNULIB_MKOSTEMPS@
+# if address@hidden@
+/* 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 address@hidden@
+/* 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
index 0000000..4327ec4
--- /dev/null
+++ b/m4/mkostemps.m4
@@ -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
index 0000000..004bf8b
--- /dev/null
+++ b/m4/mkstemps.m4
@@ -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
+])
diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4
index 42d551d..4556ac0 100644
--- a/m4/stdlib_h.m4
+++ b/m4/stdlib_h.m4
@@ -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
index 0000000..54c55e6
--- /dev/null
+++ b/modules/mkostemps
@@ -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
index 0000000..14f4698
--- /dev/null
+++ b/modules/mkstemps
@@ -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
diff --git a/modules/stdlib b/modules/stdlib
index 4968ce7..2e04088 100644
--- a/modules/stdlib
+++ b/modules/stdlib
@@ -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' \
-- 
1.6.4.2


>From 925b958e412190bedad1e935b922b75ac9c6e567 Mon Sep 17 00:00:00 2001
From: Eric Blake <address@hidden>
Date: Mon, 2 Nov 2009 16:11:18 -0700
Subject: [PATCH 3/3] stdlib-safer: wrap all mkstemp variants

* modules/mkostemp (configure.ac): Set witness.
* modules/mkostemps (configure.ac): Likewise.
* modules/mkstemps (configure.ac): Likewise.
* lib/stdlib-safer.h (mkostemp_safer, mkostemps_safer)
(mkstemps_safer): Wrap more functions.
* lib/stdlib--.h (mkostemp, mkostemps, mkstemps): Default the
wrapping.
* lib/mkstemp-safer.c (mkostemp_safer, mkostemps_safer)
(mkstemps_safer): Implement the wrappers.

Signed-off-by: Eric Blake <address@hidden>
---
 ChangeLog           |   11 +++++++++++
 lib/mkstemp-safer.c |   31 ++++++++++++++++++++++++++++++-
 lib/stdlib--.h      |   14 +++++++++++++-
 lib/stdlib-safer.h  |   14 +++++++++++++-
 modules/mkostemp    |    1 +
 modules/mkostemps   |    1 +
 modules/mkstemps    |    1 +
 7 files changed, 70 insertions(+), 3 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4d9704c..c0cc594 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2009-11-02  Eric Blake  <address@hidden>

+       stdlib-safer: wrap all mkstemp variants
+       * modules/mkostemp (configure.ac): Set witness.
+       * modules/mkostemps (configure.ac): Likewise.
+       * modules/mkstemps (configure.ac): Likewise.
+       * lib/stdlib-safer.h (mkostemp_safer, mkostemps_safer)
+       (mkstemps_safer): Wrap more functions.
+       * lib/stdlib--.h (mkostemp, mkostemps, mkstemps): Default the
+       wrapping.
+       * lib/mkstemp-safer.c (mkostemp_safer, mkostemps_safer)
+       (mkstemps_safer): Implement the wrappers.
+
        mkstemps, mkostemps: new modules
        * modules/mkostemps: New module.
        * modules/mkstemps: Likewise.
diff --git a/lib/mkstemp-safer.c b/lib/mkstemp-safer.c
index 4ba97c3..95d315b 100644
--- a/lib/mkstemp-safer.c
+++ b/lib/mkstemp-safer.c
@@ -1,6 +1,6 @@
 /* Invoke mkstemp, but avoid some glitches.

-   Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006, 2007, 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
@@ -32,3 +32,32 @@ mkstemp_safer (char *templ)
 {
   return fd_safer (mkstemp (templ));
 }
+
+#if GNULIB_MKOSTEMP
+/* Like mkostemp, but do not return STDIN_FILENO, STDOUT_FILENO, or
+   STDERR_FILENO.  */
+int
+mkostemp_safer (char *templ, int flags)
+{
+  return fd_safer (mkostemp (templ, flags));
+}
+#endif
+
+#if GNULIB_MKOSTEMPS
+/* Like mkostemps, but do not return STDIN_FILENO, STDOUT_FILENO, or
+   STDERR_FILENO.  */
+int
+mkostemps_safer (char *templ, int suffixlen, int flags)
+{
+  return fd_safer (mkostemps (templ, suffixlen, flags));
+}
+#endif
+
+#if GNULIB_MKSTEMPS
+/* Like mkstemps, but do not return STDIN_FILENO, STDOUT_FILENO, or
+   STDERR_FILENO.  */
+int mkstemps_safer (char *templ, int suffixlen)
+{
+  return fd_safer (mkstemps (templ, suffixlen));
+}
+#endif
diff --git a/lib/stdlib--.h b/lib/stdlib--.h
index 495d0eb..91268c9 100644
--- a/lib/stdlib--.h
+++ b/lib/stdlib--.h
@@ -1,6 +1,6 @@
 /* Like stdlib.h, but redefine some names to avoid glitches.

-   Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 2005, 2006, 2007, 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
@@ -22,3 +22,15 @@

 #undef mkstemp
 #define mkstemp mkstemp_safer
+
+#if GNULIB_MKOSTEMP
+# define mkostemp mkostemp_safer
+#endif
+
+#if GNULIB_MKOSTEMPS
+# define mkostemps mkostemps_safer
+#endif
+
+#if GNULIB_MKSTEMPS
+# define mkstemps mkstemps_safer
+#endif
diff --git a/lib/stdlib-safer.h b/lib/stdlib-safer.h
index a014372..c28897c 100644
--- a/lib/stdlib-safer.h
+++ b/lib/stdlib-safer.h
@@ -1,6 +1,6 @@
 /* Invoke stdlib.h functions, but avoid some glitches.

-   Copyright (C) 2005 Free Software Foundation, Inc.
+   Copyright (C) 2005, 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
@@ -18,3 +18,15 @@
 /* Written by Paul Eggert.  */

 int mkstemp_safer (char *);
+
+#if GNULIB_MKOSTEMP
+int mkostemp_safer (char *, int);
+#endif
+
+#if GNULIB_MKOSTEMPS
+int mkostemps_safer (char *, int, int);
+#endif
+
+#if GNULIB_MKSTEMPS
+int mkstemps_safer (char *, int);
+#endif
diff --git a/modules/mkostemp b/modules/mkostemp
index e336b90..8a61dbe 100644
--- a/modules/mkostemp
+++ b/modules/mkostemp
@@ -13,6 +13,7 @@ tempname

 configure.ac:
 gl_FUNC_MKOSTEMP
+gl_MODULE_INDICATOR([mkostemp])
 gl_STDLIB_MODULE_INDICATOR([mkostemp])

 Makefile.am:
diff --git a/modules/mkostemps b/modules/mkostemps
index 54c55e6..a4175bd 100644
--- a/modules/mkostemps
+++ b/modules/mkostemps
@@ -13,6 +13,7 @@ tempname

 configure.ac:
 gl_FUNC_MKOSTEMPS
+gl_MODULE_INDICATOR([mkostemps])
 gl_STDLIB_MODULE_INDICATOR([mkostemps])

 Makefile.am:
diff --git a/modules/mkstemps b/modules/mkstemps
index 14f4698..2a49777 100644
--- a/modules/mkstemps
+++ b/modules/mkstemps
@@ -12,6 +12,7 @@ tempname

 configure.ac:
 gl_FUNC_MKSTEMPS
+gl_MODULE_INDICATOR([mkstemps])
 gl_STDLIB_MODULE_INDICATOR([mkstemps])

 Makefile.am:
-- 
1.6.4.2







reply via email to

[Prev in Thread] Current Thread [Next in Thread]