Import mkdtemp gnulib module, fix mingw build

Building with mingw currently fails:

  CXX    unittests/mkdir-recursive-selftests.o
/home/emaisin/src/binutils-gdb/gdb/unittests/mkdir-recursive-selftests.c: In function ‘void selftests::mkdir_recursive::test()’:
/home/emaisin/src/binutils-gdb/gdb/unittests/mkdir-recursive-selftests.c:49:20: error: ‘mkdtemp’ was not declared in this scope
   if (mkdtemp (base) == NULL)
                    ^
Commit

    e418a61a67 ("Move mkdir_recursive to common/filestuff.c")

moved this code, but also removed the HAVE_MKDTEMP guard which prevented
the mkdtemp call to be compiled on mingw.

We can either put back the HAVE_MKDTEMP ifdef, or import the gnulib
mkdtemp module, which provides the function for mingw.  Since the
mkdir_recursive is susceptible to be used on mingw at some point, I
think it would be nice to have it tested on mingw, so I did the latter.

Once built, I tested it on Windows (copied the resulting gdb.exe on a
Windows machine, ran it, and ran "maint selftest mkdir_recursive").  It
failed, because the temporary directory is hardcoded to "/tmp/...".  I
therefore added and used a new get_standard_temp_dir function, which
returns an appropriate temporary directory for the host platform.

gdb/ChangeLog:

	* common/pathstuff.c (get_standard_temp_dir): New.
	* common/pathstuff.h (get_standard_temp_dir): New.
	* config.in: Re-generate.
	* configure: Re-generate.
	* configure.ac: Don't check for mkdtemp.
	* gnulib/aclocal-m4-deps.mk: Re-generate.
	* gnulib/aclocal.m4: Re-generate.
	* gnulib/config.in: Re-generate.
	* gnulib/configure: Re-generate.
	* gnulib/import/Makefile.am: Re-generate.
	* gnulib/import/Makefile.in: Re-generate.
	* gnulib/import/m4/gnulib-cache.m4: Re-generate.
	* gnulib/import/m4/gnulib-comp.m4: Re-generate.
	* gnulib/import/m4/mkdtemp.m4: New file.
	* gnulib/import/mkdtemp.c: New file.
	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES):
	Add mkdtemp module.
	* unittests/mkdir-recursive-selftests.c (test): Use
	get_standard_temp_dir.
	(_initialize_mkdir_recursive_selftests): Remove HAVE_MKDTEMP
	ifdef.
	* compile/compile.c (get_compile_file_tempdir): Likewise.
This commit is contained in:
Simon Marchi 2018-11-01 15:40:43 -04:00
parent 33ea299c25
commit e8d8cce69b
19 changed files with 217 additions and 27 deletions

View File

@ -1,3 +1,28 @@
2018-11-01 Simon Marchi <simon.marchi@ericsson.com>
* common/pathstuff.c (get_standard_temp_dir): New.
* common/pathstuff.h (get_standard_temp_dir): New.
* config.in: Re-generate.
* configure: Re-generate.
* configure.ac: Don't check for mkdtemp.
* gnulib/aclocal-m4-deps.mk: Re-generate.
* gnulib/aclocal.m4: Re-generate.
* gnulib/config.in: Re-generate.
* gnulib/configure: Re-generate.
* gnulib/import/Makefile.am: Re-generate.
* gnulib/import/Makefile.in: Re-generate.
* gnulib/import/m4/gnulib-cache.m4: Re-generate.
* gnulib/import/m4/gnulib-comp.m4: Re-generate.
* gnulib/import/m4/mkdtemp.m4: New file.
* gnulib/import/mkdtemp.c: New file.
* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES):
Add mkdtemp module.
* unittests/mkdir-recursive-selftests.c (test): Use
get_standard_temp_dir.
(_initialize_mkdir_recursive_selftests): Remove HAVE_MKDTEMP
ifdef.
* compile/compile.c (get_compile_file_tempdir): Likewise.
2018-11-01 Sangamesh Mallayya <sangamesh.swamy@in.ibm.com>
* rs6000-aix-tdep.c: Include "trad-frame.h" and "frame-unwind.h".

View File

@ -193,6 +193,31 @@ get_standard_cache_dir ()
/* See common/pathstuff.h. */
std::string
get_standard_temp_dir ()
{
#ifdef WIN32
const char *tmp = getenv ("TMP");
if (tmp != nullptr)
return tmp;
tmp = getenv ("TEMP");
if (tmp != nullptr)
return tmp;
error (_("Couldn't find temp dir path, both TMP and TEMP are unset."));
#else
const char *tmp = getenv ("TMPDIR");
if (tmp != nullptr)
return tmp;
return "/tmp";
#endif
}
/* See common/pathstuff.h. */
const char *
get_shell ()
{

View File

@ -66,6 +66,16 @@ extern bool contains_dir_separator (const char *path);
extern std::string get_standard_cache_dir ();
/* Get the usual temporary directory for the current platform.
On Windows, this is the TMP or TEMP environment variable.
On the rest, this is the TMPDIR environment variable, if defined, else /tmp.
Throw an exception on error. */
extern std::string get_standard_temp_dir ();
/* Return the file name of the user's shell. Normally this comes from
the SHELL environment variable. */

View File

@ -395,11 +395,7 @@ get_compile_file_tempdir (void)
strcpy (tname, TEMPLATE);
#undef TEMPLATE
#ifdef HAVE_MKDTEMP
tempdir_name = mkdtemp (tname);
#else
error (_("Command not supported on this host."));
#endif
if (tempdir_name == NULL)
perror_with_name (_("Could not make temporary directory"));

View File

@ -288,9 +288,6 @@
/* Define to 1 if you have the <memory.h> header file. */
#undef HAVE_MEMORY_H
/* Define to 1 if you have the `mkdtemp' function. */
#undef HAVE_MKDTEMP
/* Define to 1 if you have a working `mmap' system call. */
#undef HAVE_MMAP

2
gdb/configure vendored
View File

@ -13320,7 +13320,7 @@ for ac_func in getauxval getrusage getuid getgid \
sigaction sigprocmask sigsetmask socketpair \
ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
setrlimit getrlimit posix_madvise waitpid \
ptrace64 sigaltstack mkdtemp setns
ptrace64 sigaltstack setns
do :
as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"

View File

@ -1359,7 +1359,7 @@ AC_CHECK_FUNCS([getauxval getrusage getuid getgid \
sigaction sigprocmask sigsetmask socketpair \
ttrace wborder wresize setlocale iconvlist libiconvlist btowc \
setrlimit getrlimit posix_madvise waitpid \
ptrace64 sigaltstack mkdtemp setns])
ptrace64 sigaltstack setns])
AM_LANGINFO_CODESET
GDB_AC_COMMON

View File

@ -80,6 +80,7 @@ aclocal_m4_deps = \
import/m4/mempcpy.m4 \
import/m4/memrchr.m4 \
import/m4/mkdir.m4 \
import/m4/mkdtemp.m4 \
import/m4/mkostemp.m4 \
import/m4/mmap-anon.m4 \
import/m4/mode_t.m4 \

View File

@ -1353,6 +1353,7 @@ m4_include([import/m4/memmem.m4])
m4_include([import/m4/mempcpy.m4])
m4_include([import/m4/memrchr.m4])
m4_include([import/m4/mkdir.m4])
m4_include([import/m4/mkdtemp.m4])
m4_include([import/m4/mkostemp.m4])
m4_include([import/m4/mmap-anon.m4])
m4_include([import/m4/mode_t.m4])

View File

@ -203,6 +203,9 @@
/* Define to 1 when the gnulib module memrchr should be tested. */
#undef GNULIB_TEST_MEMRCHR
/* Define to 1 when the gnulib module mkdtemp should be tested. */
#undef GNULIB_TEST_MKDTEMP
/* Define to 1 when the gnulib module mkostemp should be tested. */
#undef GNULIB_TEST_MKOSTEMP
@ -548,6 +551,9 @@
when it succeeds. */
#undef HAVE_MINIMALLY_WORKING_GETCWD
/* Define to 1 if you have the `mkdtemp' function. */
#undef HAVE_MKDTEMP
/* Define to 1 if you have the 'mkostemp' function. */
#undef HAVE_MKOSTEMP

47
gdb/gnulib/configure vendored
View File

@ -5841,6 +5841,7 @@ fi
# Code from module mempcpy:
# Code from module memrchr:
# Code from module mkdir:
# Code from module mkdtemp:
# Code from module mkostemp:
# Code from module msvc-inval:
# Code from module msvc-nothrow:
@ -21891,6 +21892,52 @@ $as_echo "#define FUNC_MKDIR_DOT_BUG 1" >>confdefs.h
fi
for ac_func in mkdtemp
do :
ac_fn_c_check_func "$LINENO" "mkdtemp" "ac_cv_func_mkdtemp"
if test "x$ac_cv_func_mkdtemp" = xyes; then :
cat >>confdefs.h <<_ACEOF
#define HAVE_MKDTEMP 1
_ACEOF
fi
done
if test $ac_cv_func_mkdtemp = no; then
HAVE_MKDTEMP=0
fi
if test $HAVE_MKDTEMP = 0; then
gl_LIBOBJS="$gl_LIBOBJS mkdtemp.$ac_objext"
:
fi
GNULIB_MKDTEMP=1
$as_echo "#define GNULIB_TEST_MKDTEMP 1" >>confdefs.h

View File

@ -21,7 +21,7 @@
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkostemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkdtemp mkostemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
AUTOMAKE_OPTIONS = 1.9.6 gnits
@ -1223,6 +1223,15 @@ EXTRA_libgnu_a_SOURCES += mkdir.c
## end gnulib module mkdir
## begin gnulib module mkdtemp
EXTRA_DIST += mkdtemp.c
EXTRA_libgnu_a_SOURCES += mkdtemp.c
## end gnulib module mkdtemp
## begin gnulib module mkostemp

View File

@ -35,7 +35,7 @@
# the same distribution terms as the rest of that program.
#
# Generated by gnulib-tool.
# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkostemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
# Reproduce by: gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkdtemp mkostemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
@ -192,6 +192,7 @@ am__aclocal_m4_deps = $(top_srcdir)/import/m4/00gnulib.m4 \
$(top_srcdir)/import/m4/mempcpy.m4 \
$(top_srcdir)/import/m4/memrchr.m4 \
$(top_srcdir)/import/m4/mkdir.m4 \
$(top_srcdir)/import/m4/mkdtemp.m4 \
$(top_srcdir)/import/m4/mkostemp.m4 \
$(top_srcdir)/import/m4/mmap-anon.m4 \
$(top_srcdir)/import/m4/mode_t.m4 \
@ -1515,9 +1516,9 @@ EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h arpa_inet.in.h \
malloca.valgrind math.in.h mbrtowc.c mbsinit.c \
mbsrtowcs-impl.h mbsrtowcs-state.c mbsrtowcs.c memchr.c \
memchr.valgrind memmem.c str-two-way.h mempcpy.c memrchr.c \
mkdir.c mkostemp.c msvc-inval.c msvc-inval.h msvc-nothrow.c \
msvc-nothrow.h netinet_in.in.h open.c openat.c openat.h \
dirent-private.h opendir.c pathmax.h rawmemchr.c \
mkdir.c mkdtemp.c mkostemp.c msvc-inval.c msvc-inval.h \
msvc-nothrow.c msvc-nothrow.h netinet_in.in.h open.c openat.c \
openat.h dirent-private.h opendir.c pathmax.h rawmemchr.c \
rawmemchr.valgrind dirent-private.h readdir.c readlink.c \
realloc.c rename.c dirent-private.h rewinddir.c rmdir.c \
same-inode.h save-cwd.h secure_getenv.c setenv.c signal.in.h \
@ -1587,11 +1588,11 @@ EXTRA_libgnu_a_SOURCES = alloca.c openat-proc.c canonicalize-lgpl.c \
gettimeofday.c glob.c inet_ntop.c isnan.c isnand.c isnan.c \
isnanl.c lstat.c malloc.c mbrtowc.c mbsinit.c \
mbsrtowcs-state.c mbsrtowcs.c memchr.c memmem.c mempcpy.c \
memrchr.c mkdir.c mkostemp.c msvc-inval.c msvc-nothrow.c \
open.c openat.c opendir.c rawmemchr.c readdir.c readlink.c \
realloc.c rename.c rewinddir.c rmdir.c secure_getenv.c \
setenv.c stat.c strchrnul.c strdup.c strerror.c \
strerror-override.c strstr.c strtok_r.c unsetenv.c
memrchr.c mkdir.c mkdtemp.c mkostemp.c msvc-inval.c \
msvc-nothrow.c open.c openat.c opendir.c rawmemchr.c readdir.c \
readlink.c realloc.c rename.c rewinddir.c rmdir.c \
secure_getenv.c setenv.c stat.c strchrnul.c strdup.c \
strerror.c strerror-override.c strstr.c strtok_r.c unsetenv.c
# Use this preprocessor expression to decide whether #include_next works.
# Do not rely on a 'configure'-time test for this, since the expression
@ -1722,6 +1723,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mempcpy.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memrchr.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkdir.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkdtemp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/mkostemp.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msvc-inval.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/msvc-nothrow.Po@am__quote@

View File

@ -27,7 +27,7 @@
# Specification in the form of a command-line invocation:
# gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkostemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
# gnulib-tool --import --lib=libgnu --source-base=import --m4-base=import/m4 --doc-base=doc --tests-base=tests --aux-dir=import/extra --no-conditional-dependencies --no-libtool --macro-prefix=gl --no-vc-files alloca canonicalize-lgpl dirent dirfd errno fnmatch-gnu frexpl getcwd glob inet_ntop inttypes limits-h lstat memchr memmem mkdir mkdtemp mkostemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
# Specification in the form of a few gnulib-tool.m4 macro invocations:
gl_LOCAL_DIR([])
@ -48,6 +48,7 @@ gl_MODULES([
memchr
memmem
mkdir
mkdtemp
mkostemp
pathmax
rawmemchr

View File

@ -121,6 +121,7 @@ AC_DEFUN([gl_EARLY],
# Code from module mempcpy:
# Code from module memrchr:
# Code from module mkdir:
# Code from module mkdtemp:
# Code from module mkostemp:
# Code from module msvc-inval:
# Code from module msvc-nothrow:
@ -444,6 +445,12 @@ AC_DEFUN([gl_INIT],
if test $REPLACE_MKDIR = 1; then
AC_LIBOBJ([mkdir])
fi
gl_FUNC_MKDTEMP
if test $HAVE_MKDTEMP = 0; then
AC_LIBOBJ([mkdtemp])
gl_PREREQ_MKDTEMP
fi
gl_STDLIB_MODULE_INDICATOR([mkdtemp])
gl_FUNC_MKOSTEMP
if test $HAVE_MKOSTEMP = 0; then
AC_LIBOBJ([mkostemp])
@ -845,6 +852,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/mempcpy.c
lib/memrchr.c
lib/mkdir.c
lib/mkdtemp.c
lib/mkostemp.c
lib/msvc-inval.c
lib/msvc-inval.h
@ -992,6 +1000,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/mempcpy.m4
m4/memrchr.m4
m4/mkdir.m4
m4/mkdtemp.m4
m4/mkostemp.m4
m4/mmap-anon.m4
m4/mode_t.m4

View File

@ -0,0 +1,20 @@
# mkdtemp.m4 serial 8
dnl Copyright (C) 2001-2003, 2006-2007, 2009-2016 Free Software Foundation,
dnl 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_MKDTEMP],
[
AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
AC_CHECK_FUNCS([mkdtemp])
if test $ac_cv_func_mkdtemp = no; then
HAVE_MKDTEMP=0
fi
])
# Prerequisites of lib/mkdtemp.c
AC_DEFUN([gl_PREREQ_MKDTEMP],
[:
])

View File

@ -0,0 +1,39 @@
/* Copyright (C) 1999, 2001-2003, 2006-2007, 2009-2016 Free Software
Foundation, Inc.
This file is part of 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 <http://www.gnu.org/licenses/>. */
/* Extracted from misc/mkdtemp.c. */
#include <config.h>
/* Specification. */
#include <stdlib.h>
#include "tempname.h"
/* Generate a unique temporary directory from XTEMPLATE.
The last six characters of XTEMPLATE must be "XXXXXX";
they are replaced with a string that makes the filename unique.
The directory is created, mode 700, and its name is returned.
(This function comes from OpenBSD.) */
char *
mkdtemp (char *xtemplate)
{
if (gen_tempname (xtemplate, 0, 0, GT_DIR))
return NULL;
else
return xtemplate;
}

View File

@ -46,6 +46,7 @@ IMPORTED_GNULIB_MODULES="\
memchr \
memmem \
mkdir \
mkdtemp \
mkostemp \
pathmax \
rawmemchr \

View File

@ -21,6 +21,8 @@
#include "common/filestuff.h"
#include "selftest.h"
#include "common/byte-vector.h"
#include "common/pathstuff.h"
namespace selftests {
namespace mkdir_recursive {
@ -44,9 +46,10 @@ create_dir_and_check (const char *dir)
static void
test ()
{
char base[] = "/tmp/gdb-selftests-XXXXXX";
std::string tmp = get_standard_temp_dir () + "/gdb-selftests";
gdb::char_vector base = make_temp_filename (tmp);
if (mkdtemp (base) == NULL)
if (mkdtemp (base.data ()) == NULL)
perror_with_name (("mkdtemp"));
/* Try not to leave leftover directories. */
@ -66,12 +69,12 @@ test ()
private:
const char *m_base;
} cleanup_dirs (base);
} cleanup_dirs (base.data ());
std::string dir = string_printf ("%s/a/b", base);
std::string dir = string_printf ("%s/a/b", base.data ());
SELF_CHECK (create_dir_and_check (dir.c_str ()));
dir = string_printf ("%s/a/b/c//d/e/", base);
dir = string_printf ("%s/a/b/c//d/e/", base.data ());
SELF_CHECK (create_dir_and_check (dir.c_str ()));
}
@ -81,9 +84,7 @@ test ()
void
_initialize_mkdir_recursive_selftests ()
{
#if defined (HAVE_MKDTEMP)
selftests::register_test ("mkdir_recursive",
selftests::mkdir_recursive::test);
#endif
}