changeset 7338:32934cff1706

[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".
author Paul Eggert <eggert@cs.ucla.edu>
date Wed, 20 Sep 2006 18:44:04 +0000
parents 1735329d8bfd
children 9f4982d3a01e
files ChangeLog lib/ChangeLog lib/mkstemp.c lib/mkstemp.h lib/stdlib--.h m4/ChangeLog m4/mkstemp.m4 modules/mkstemp
diffstat 8 files changed, 96 insertions(+), 48 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-09-20  Paul Eggert  <eggert@cs.ucla.edu>
+
+	* 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  <ebb9@byu.net>
 
 	* gnulib-tool: Avoid space-tab.
--- a/lib/ChangeLog
+++ b/lib/ChangeLog
@@ -1,5 +1,13 @@
 2006-09-20  Paul Eggert  <eggert@cs.ucla.edu>
 
+	* 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  <drepper@redhat.com>
--- a/lib/mkstemp.c
+++ b/lib/mkstemp.c
@@ -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);
 }
new file mode 100644
--- /dev/null
+++ b/lib/mkstemp.h
@@ -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
--- 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 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
--- a/m4/ChangeLog
+++ b/m4/ChangeLog
@@ -1,3 +1,11 @@
+2006-09-20  Paul Eggert  <eggert@cs.ucla.edu>
+
+	* 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  <bruno@clisp.org>
 
 	* inttypes-h.m4 (gl_HEADER_INTTYPES_H): Remove macro.
--- a/m4/mkstemp.m4
+++ b/m4/mkstemp.m4
@@ -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])
 
-  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
--- a/modules/mkstemp
+++ b/modules/mkstemp
@@ -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:
 <stdlib.h>