# HG changeset patch # User Eric Blake # Date 1257201190 25200 # Node ID b45701f2ff71873aec3bd6a6417f0d6a19a2d54e # Parent 49e87af14a05eb3a528b4acbe648bb0b5578c904 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 diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,20 @@ 2009-11-04 Eric Blake + 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 --- a/MODULES.html.sh +++ b/MODULES.html.sh @@ -2480,6 +2480,9 @@ 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 --- /dev/null +++ b/doc/glibc-functions/mkostemps.texi @@ -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 --- /dev/null +++ b/doc/glibc-functions/mkstemps.texi @@ -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 diff --git a/doc/gnulib.texi b/doc/gnulib.texi --- a/doc/gnulib.texi +++ b/doc/gnulib.texi @@ -5079,7 +5079,9 @@ * lcong48_r:: * lrand48_r:: * mkostemp:: +* mkostemps:: * mrand48_r:: +* mkstemps:: * nrand48_r:: * on_exit:: * ptsname_r:: @@ -5120,7 +5122,9 @@ @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 --- /dev/null +++ b/lib/mkostemps.c @@ -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 . */ + +#if !_LIBC +# include +#endif + +#include + +#if !_LIBC +# include +# 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 + +#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 --- /dev/null +++ b/lib/mkstemps.c @@ -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 . */ + +#if !_LIBC +# include +#endif + +#include + +#if !_LIBC +# include +# 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 + +#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 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -224,6 +224,31 @@ 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 ) + 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 @@ 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 --- /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 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 --- /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 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 --- 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 @@ 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 @@ 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 --- /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: + + +License: +LGPLv2+ + +Maintainer: +Eric Blake diff --git a/modules/mkstemps b/modules/mkstemps new file mode 100644 --- /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: + + +License: +LGPLv2+ + +Maintainer: +Eric Blake diff --git a/modules/stdlib b/modules/stdlib --- a/modules/stdlib +++ b/modules/stdlib @@ -34,7 +34,9 @@ -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 @@ -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' \