From eea8c9224b1086e224542d442f08526ebcdfdb64 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 3 Apr 2010 13:44:41 +0200 Subject: [PATCH] mkstemp: Fix C++ test error on mingw. --- ChangeLog | 11 +++++++++- lib/stdlib.in.h | 3 +++ m4/mkstemp.m4 | 66 +++++++++++++++++++++++++++++++-------------------------- m4/stdlib_h.m4 | 3 ++- modules/stdlib | 1 + 5 files changed, 52 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index ed4e221a2..88fffb876 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,21 @@ 2010-04-03 Bruno Haible + mkstemp: Fix C++ test error on mingw. + * lib/stdlib.in.h (mkstemp): Use modern idiom. + * m4/mkstemp.m4 (gl_FUNC_MKSTEMP): Distinguish the case that the + function is missing and that it needs to be replaced. + * m4/stdlib_h.m4 (gl_STDLIB_H_DEFAULTS): Initialize HAVE_MKSTEMP. + * modules/stdlib (Makefile.am): Substitute HAVE_MKSTEMP. + +2010-04-03 Bruno Haible + stpncpy: Fix C++ test error on mingw. * lib/string.in.h (stpncpy): Use modern idiom. * m4/stpncpy.m4 (gl_FUNC_STPNCPY): Distinguish the case that the function is missing and that it needs to be replaced. * m4/string_h.m4 (gl_HEADER_STRING_H_DEFAULTS): Initialize REPLACE_STPNCPY. - * modules/string (Makefile.am): Replace REPLACE_STPNCPY. + * modules/string (Makefile.am): Substitute REPLACE_STPNCPY. 2010-04-03 Bruno Haible diff --git a/lib/stdlib.in.h b/lib/stdlib.in.h index 5c7c3f010..d74c2518b 100644 --- a/lib/stdlib.in.h +++ b/lib/stdlib.in.h @@ -329,6 +329,9 @@ _GL_WARN_ON_USE (mkostemps, "mkostemps is unportable - " _GL_FUNCDECL_RPL (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1))); _GL_CXXALIAS_RPL (mkstemp, int, (char * /*template*/)); # else +# if ! @HAVE_MKSTEMP@ +_GL_FUNCDECL_SYS (mkstemp, int, (char * /*template*/) _GL_ARG_NONNULL ((1))); +# endif _GL_CXXALIAS_SYS (mkstemp, int, (char * /*template*/)); # endif _GL_CXXALIASWARN (mkstemp); diff --git a/m4/mkstemp.m4 b/m4/mkstemp.m4 index e4fee76db..d6430a9c2 100644 --- a/m4/mkstemp.m4 +++ b/m4/mkstemp.m4 @@ -1,4 +1,4 @@ -#serial 17 +#serial 18 # Copyright (C) 2001, 2003-2007, 2009-2010 Free Software Foundation, Inc. # This file is free software; the Free Software Foundation @@ -16,35 +16,41 @@ AC_DEFUN([gl_FUNC_MKSTEMP], AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) 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 templ[] = "conftest.mkstemp/coXXXXXX"; - int (*mkstemp_function) (char *) = mkstemp; - int fd = mkstemp_function (templ); - 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 - REPLACE_MKSTEMP=1 + AC_CHECK_FUNCS_ONCE([mkstemp]) + if test $ac_cv_func_mkstemp = 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 templ[] = "conftest.mkstemp/coXXXXXX"; + int (*mkstemp_function) (char *) = mkstemp; + int fd = mkstemp_function (templ); + 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 + REPLACE_MKSTEMP=1 + AC_LIBOBJ([mkstemp]) + gl_PREREQ_MKSTEMP + fi + else + HAVE_MKSTEMP=0 AC_LIBOBJ([mkstemp]) gl_PREREQ_MKSTEMP fi diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4 index 4c5cca89a..dd84796d2 100644 --- a/m4/stdlib_h.m4 +++ b/m4/stdlib_h.m4 @@ -1,4 +1,4 @@ -# stdlib_h.m4 serial 27 +# stdlib_h.m4 serial 28 dnl Copyright (C) 2007-2010 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, @@ -85,6 +85,7 @@ AC_DEFUN([gl_STDLIB_H_DEFAULTS], HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP]) HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP]) HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS]) + HAVE_MKSTEMP=1; AC_SUBST([HAVE_MKSTEMP]) HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS]) HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME]) HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R]) diff --git a/modules/stdlib b/modules/stdlib index 26ea709f7..32a4e6405 100644 --- a/modules/stdlib +++ b/modules/stdlib @@ -62,6 +62,7 @@ stdlib.h: stdlib.in.h $(CXXDEFS_H) $(ARG_NONNULL_H) $(WARN_ON_USE_H) -e 's|@''HAVE_MKDTEMP''@|$(HAVE_MKDTEMP)|g' \ -e 's|@''HAVE_MKOSTEMP''@|$(HAVE_MKOSTEMP)|g' \ -e 's|@''HAVE_MKOSTEMPS''@|$(HAVE_MKOSTEMPS)|g' \ + -e 's|@''HAVE_MKSTEMP''@|$(HAVE_MKSTEMP)|g' \ -e 's|@''HAVE_MKSTEMPS''@|$(HAVE_MKSTEMPS)|g' \ -e 's|@''HAVE_PTSNAME''@|$(HAVE_PTSNAME)|g' \ -e 's|@''HAVE_RANDOM_H''@|$(HAVE_RANDOM_H)|g' \ -- 2.11.0