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
e418a61a67a ("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.
+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".
/* 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 ()
{
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. */
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"));
/* 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
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"
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
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 \
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])
/* 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
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
# 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:
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
+
+
+
+
+
# 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
## 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
# 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
$(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 \
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 \
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
@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@
# 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([])
memchr
memmem
mkdir
+ mkdtemp
mkostemp
pathmax
rawmemchr
# 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:
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])
lib/mempcpy.c
lib/memrchr.c
lib/mkdir.c
+ lib/mkdtemp.c
lib/mkostemp.c
lib/msvc-inval.c
lib/msvc-inval.h
m4/mempcpy.m4
m4/memrchr.m4
m4/mkdir.m4
+ m4/mkdtemp.m4
m4/mkostemp.m4
m4/mmap-anon.m4
m4/mode_t.m4
--- /dev/null
+# 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],
+[:
+])
--- /dev/null
+/* 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;
+}
memchr \
memmem \
mkdir \
+ mkdtemp \
mkostemp \
pathmax \
rawmemchr \
#include "common/filestuff.h"
#include "selftest.h"
+#include "common/byte-vector.h"
+#include "common/pathstuff.h"
namespace selftests {
namespace mkdir_recursive {
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. */
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 ()));
}
void
_initialize_mkdir_recursive_selftests ()
{
-#if defined (HAVE_MKDTEMP)
selftests::register_test ("mkdir_recursive",
selftests::mkdir_recursive::test);
-#endif
}