Eric Blake <[EMAIL PROTECTED]> writes: > Thanks for the report. Which platform, which compiler, and which version > of coreutils was this? If it is still present in coreutils 6.2, we would > like to get it fixed before 6.3.
Yes, likewise. Looking at the implementation, it seems like there are some obvious checks to add, e.g., that one can seek to a 4 GiB boundary in a mkstemp file. Also, there are some naming problems, since some stdlib.h have "#define mkstemp ..." in some situations, and this runs afoul of config.h's "#define mkstmep rpl_mkstemp". I don't know whether the following patch will fix his problem (we need more info for that) but I don't see how it could hurt, so I installed it into gnulib. 2006-09-20 Paul Eggert <[EMAIL PROTECTED]> * modules/mkstemp (Depends-on): Add extensions, so that mkstemp is visible on some platforms. (Makefile.am): Add mkstemp.h to EXTRA_DIST. (Include): Change to "mkstemp.h" from <stdlib.h>. * lib/mkstemp.h: New file, since some standard headers #define mkstemp. * lib/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. * lib/stdlib--.h: Include mkstemp.h. * m4/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". Index: modules/mkstemp =================================================================== RCS file: /cvsroot/gnulib/gnulib/modules/mkstemp,v retrieving revision 1.8 diff -p -u -r1.8 mkstemp --- modules/mkstemp 21 Aug 2006 06:11:26 -0000 1.8 +++ modules/mkstemp 20 Sep 2006 18:47:22 -0000 @@ -7,6 +7,7 @@ lib/tempname.c m4/mkstemp.m4 Depends-on: +extensions stat-macros stdint sys_stat @@ -15,9 +16,10 @@ configure.ac: gl_FUNC_MKSTEMP Makefile.am: +EXTRA_DIST += mkstemp.h Include: -<stdlib.h> +"mkstemp.h" License: GPL Index: lib/mkstemp.h =================================================================== RCS file: lib/mkstemp.h diff -N lib/mkstemp.h --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ lib/mkstemp.h 20 Sep 2006 18:43:20 -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 <stdlib.h> + +#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 Index: lib/mkstemp.c =================================================================== RCS file: /cvsroot/gnulib/gnulib/lib/mkstemp.c,v retrieving revision 1.7 diff -u -r1.7 mkstemp.c --- lib/mkstemp.c 13 Sep 2006 22:38:14 -0000 1.7 +++ lib/mkstemp.c 20 Sep 2006 18:43:20 -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 <config.h> - -/* 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 <config.h> +# include "mkstemp.h" +int __gen_tempname (); +#endif #include <stdio.h> #include <stdlib.h> @@ -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); } Index: lib/stdlib--.h =================================================================== RCS file: /cvsroot/gnulib/gnulib/lib/stdlib--.h,v retrieving revision 1.1 diff -u -r1.1 stdlib--.h --- lib/stdlib--.h 27 Aug 2005 20:12:02 -0000 1.1 +++ lib/stdlib--.h 20 Sep 2006 18:43:20 -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 <stdlib.h> #include "stdlib-safer.h" +#include "mkstemp.h" #undef mkstemp #define mkstemp mkstemp_safer Index: m4/mkstemp.m4 =================================================================== RCS file: /cvsroot/gnulib/gnulib/m4/mkstemp.m4,v retrieving revision 1.18 diff -u -r1.18 mkstemp.m4 --- m4/mkstemp.m4 21 Aug 2006 06:11:26 -0000 1.18 +++ m4/mkstemp.m4 20 Sep 2006 18:43:20 -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 <stdlib.h> -# include <unistd.h> - 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]) + + 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_mkstemp_limitations = yes; then + 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