# HG changeset patch # User Paul Eggert # Date 1158777844 0 # Node ID 32934cff17060aafadb63bc8720283b5f4f95f93 # Parent 1735329d8bfd5e21cc44bb78463e77caf9af5df3 [ChangeLog] * modules/mkstemp (Depends-on): Add extensions, so that mkstemp is visible on some platforms. (Makefile.am): Add mkstemp.h to EXTRA_DIST. [lib/ChangeLog] * mkstemp.h: New file, since some standard headers #define mkstemp. * mkstemp.c: Revamp to put the !_LIBC code together. Include "mkstemp.h". Make the _LIBC code resemble glibc original more, e.g., use K&R style. * stdlib--.h: Include mkstemp.h. [m4/ChangeLog] * mkstemp.m4 (gl_FUNC_MKSTEMP): Require AC_SYS_LARGEFILE. Check that large offsets work. Modernize Autoconf usages. Prefer "yes" to mean a good thing rather than a bad. Don't put "#define mkstemp" in config.h, as this might interfere with standard system headers that "#define mkstemp mkstemp64". diff -r 1735329d8bfd -r 32934cff1706 ChangeLog --- a/ChangeLog Wed Sep 20 18:38:14 2006 +0000 +++ b/ChangeLog Wed Sep 20 18:44:04 2006 +0000 @@ -1,3 +1,9 @@ +2006-09-20 Paul Eggert + + * modules/mkstemp (Depends-on): Add extensions, so that + mkstemp is visible on some platforms. + (Makefile.am): Add mkstemp.h to EXTRA_DIST. + 2006-09-19 Eric Blake * gnulib-tool: Avoid space-tab. diff -r 1735329d8bfd -r 32934cff1706 lib/ChangeLog --- a/lib/ChangeLog Wed Sep 20 18:38:14 2006 +0000 +++ b/lib/ChangeLog Wed Sep 20 18:44:04 2006 +0000 @@ -1,5 +1,13 @@ 2006-09-20 Paul Eggert + * mkstemp.h: New file, since some standard headers + #define mkstemp. + * mkstemp.c: Revamp to put the !_LIBC code together. + Include "mkstemp.h". + Make the _LIBC code resemble glibc original more, + e.g., use K&R style. + * stdlib--.h: Include mkstemp.h. + Import this patch from libc: 2006-04-07 Ulrich Drepper diff -r 1735329d8bfd -r 32934cff1706 lib/mkstemp.c --- a/lib/mkstemp.c Wed Sep 20 18:38:14 2006 +0000 +++ b/lib/mkstemp.c Wed Sep 20 18:44:04 2006 +0000 @@ -15,12 +15,11 @@ with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ -#include - -/* Disable the definition of mkstemp to rpl_mkstemp (from config.h) in this - file. Otherwise, we'd get conflicting prototypes for rpl_mkstemp on - most systems. */ -#undef mkstemp +#if !_LIBC +# include +# include "mkstemp.h" +int __gen_tempname (); +#endif #include #include @@ -29,14 +28,13 @@ # define __GT_FILE 0 #endif -int __gen_tempname (); - /* 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 -rpl_mkstemp (char *template) +mkstemp (template) + char *template; { return __gen_tempname (template, __GT_FILE); } diff -r 1735329d8bfd -r 32934cff1706 lib/mkstemp.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lib/mkstemp.h Wed Sep 20 18:44:04 2006 +0000 @@ -0,0 +1,30 @@ +/* Create a unique temporary file. + + Copyright (C) 2006 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 + the Free Software Foundation; either version 2, 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, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + +/* written by Jim Meyering */ + +#include + +#ifdef __MKSTEMP_PREFIX +# define _GL_CONCAT(x, y) x ## y +# define _GL_XCONCAT(x, y) _GL_CONCAT (x, y) +# define __MKSTEMP_ID(y) _GL_XCONCAT (__MKSTEMP_PREFIX, y) +# undef mkstemp +# define mkstemp __MKSTEMP_ID (mkstemp) +int mkstemp (char *); +#endif diff -r 1735329d8bfd -r 32934cff1706 lib/stdlib--.h --- a/lib/stdlib--.h Wed Sep 20 18:38:14 2006 +0000 +++ b/lib/stdlib--.h Wed Sep 20 18:44:04 2006 +0000 @@ -1,6 +1,6 @@ /* Like stdlib.h, but redefine some names to avoid glitches. - Copyright (C) 2005 Free Software Foundation, Inc. + Copyright (C) 2005, 2006 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 @@ -21,5 +21,6 @@ #include #include "stdlib-safer.h" +#include "mkstemp.h" #undef mkstemp #define mkstemp mkstemp_safer diff -r 1735329d8bfd -r 32934cff1706 m4/ChangeLog --- a/m4/ChangeLog Wed Sep 20 18:38:14 2006 +0000 +++ b/m4/ChangeLog Wed Sep 20 18:44:04 2006 +0000 @@ -1,3 +1,11 @@ +2006-09-20 Paul Eggert + + * mkstemp.m4 (gl_FUNC_MKSTEMP): Require AC_SYS_LARGEFILE. + Check that large offsets work. Modernize Autoconf usages. + Prefer "yes" to mean a good thing rather than a bad. + Don't put "#define mkstemp" in config.h, as this might interfere + with standard system headers that "#define mkstemp mkstemp64". + 2006-09-18 Bruno Haible * inttypes-h.m4 (gl_HEADER_INTTYPES_H): Remove macro. diff -r 1735329d8bfd -r 32934cff1706 m4/mkstemp.m4 --- a/m4/mkstemp.m4 Wed Sep 20 18:38:14 2006 +0000 +++ b/m4/mkstemp.m4 Wed Sep 20 18:44:04 2006 +0000 @@ -1,4 +1,4 @@ -#serial 13 +#serial 14 # Copyright (C) 2001, 2003, 2004, 2005, 2006 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -12,46 +12,41 @@ # only 32 files per process. # On systems like the above, arrange to use the replacement function. AC_DEFUN([gl_FUNC_MKSTEMP], -[dnl - AC_REPLACE_FUNCS(mkstemp) - if test $ac_cv_func_mkstemp = no; then - gl_cv_func_mkstemp_limitations=yes - else - AC_CACHE_CHECK([for mkstemp limitations], - gl_cv_func_mkstemp_limitations, - [ - mkdir conftest.mkstemp - AC_TRY_RUN([ -# include -# include - int main () - { - int i; - for (i = 0; i < 70; i++) - { - char template[] = "conftest.mkstemp/coXXXXXX"; - int fd = mkstemp (template); - if (fd == -1) - exit (1); - close (fd); - } - exit (0); - } - ], - gl_cv_func_mkstemp_limitations=no, - gl_cv_func_mkstemp_limitations=yes, - gl_cv_func_mkstemp_limitations=yes - ) - rm -rf conftest.mkstemp - ] - ) - fi +[ + AC_REQUIRE([AC_SYS_LARGEFILE]) - if test $gl_cv_func_mkstemp_limitations = yes; then + AC_CACHE_CHECK([for working mkstemp], + [gl_cv_func_working_mkstemp], + [ + mkdir conftest.mkstemp + AC_RUN_IFELSE( + [AC_LANG_PROGRAM( + [AC_INCLUDES_DEFAULT], + [[int i; + off_t large = (off_t) 4294967295u; + if (large < 0) + large = 2147483647; + for (i = 0; i < 70; i++) + { + char template[] = "conftest.mkstemp/coXXXXXX"; + int (*mkstemp_function) (char *) = mkstemp; + int fd = mkstemp_function (template); + if (fd < 0 || lseek (fd, large, SEEK_SET) != large) + return 1; + close (fd); + } + return 0;]])], + [gl_cv_func_working_mkstemp=yes], + [gl_cv_func_working_mkstemp=no], + [gl_cv_func_working_mkstemp=no]) + rm -rf conftest.mkstemp + ]) + + if test $gl_cv_func_working_mkstemp != yes; then + AC_DEFINE([__MKSTEMP_PREFIX], [[rpl_]], + [Define to rpl_ if the mkstemp replacement function should be used.]) AC_LIBOBJ(mkstemp) AC_LIBOBJ(tempname) - AC_DEFINE(mkstemp, rpl_mkstemp, - [Define to rpl_mkstemp if the replacement function should be used.]) gl_PREREQ_MKSTEMP gl_PREREQ_TEMPNAME fi diff -r 1735329d8bfd -r 32934cff1706 modules/mkstemp --- a/modules/mkstemp Wed Sep 20 18:38:14 2006 +0000 +++ b/modules/mkstemp Wed Sep 20 18:44:04 2006 +0000 @@ -7,6 +7,7 @@ m4/mkstemp.m4 Depends-on: +extensions stat-macros stdint sys_stat @@ -15,6 +16,7 @@ gl_FUNC_MKSTEMP Makefile.am: +EXTRA_DIST += mkstemp.h Include: