[v3,3/5] Import gnulib's mkdir module

Message ID 1532979934-25275-4-git-send-email-simon.marchi@ericsson.com
State New, archived
Headers

Commit Message

Simon Marchi July 30, 2018, 7:45 p.m. UTC
  The following patch makes use of the mkdir function.  Import the mkdir
gnulib module to ensure proper operation on all platforms.

gdb/ChangeLog:

	* 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/mkdir.m4: New file.
	* gnulib/import/mkdir.c: New file.
	* gnulib/update-gnulib.sh (IMPORTED_GNULIB_MODULES): Add mkdir
	module.
---
 gdb/gnulib/aclocal.m4                |   1 +
 gdb/gnulib/config.in                 |   4 ++
 gdb/gnulib/configure                 | 126 +++++++++++++++++++++++++++++++++++
 gdb/gnulib/import/Makefile.am        |  11 ++-
 gdb/gnulib/import/Makefile.in        |  16 +++--
 gdb/gnulib/import/m4/gnulib-cache.m4 |   3 +-
 gdb/gnulib/import/m4/gnulib-comp.m4  |   7 ++
 gdb/gnulib/import/m4/mkdir.m4        |  69 +++++++++++++++++++
 gdb/gnulib/import/mkdir.c            |  93 ++++++++++++++++++++++++++
 gdb/gnulib/update-gnulib.sh          |   1 +
 10 files changed, 322 insertions(+), 9 deletions(-)
 create mode 100644 gdb/gnulib/import/m4/mkdir.m4
 create mode 100644 gdb/gnulib/import/mkdir.c
  

Patch

diff --git a/gdb/gnulib/aclocal.m4 b/gdb/gnulib/aclocal.m4
index 276b9bb..b897337 100644
--- a/gdb/gnulib/aclocal.m4
+++ b/gdb/gnulib/aclocal.m4
@@ -1350,6 +1350,7 @@  m4_include([import/m4/memchr.m4])
 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/mkstemp.m4])
 m4_include([import/m4/mmap-anon.m4])
 m4_include([import/m4/mode_t.m4])
diff --git a/gdb/gnulib/config.in b/gdb/gnulib/config.in
index 543eb8b..41351ea 100644
--- a/gdb/gnulib/config.in
+++ b/gdb/gnulib/config.in
@@ -64,6 +64,10 @@ 
    MSVC and with C++ compilers. */
 #undef FLEXIBLE_ARRAY_MEMBER
 
+/* Define to 1 if mkdir mistakenly creates a directory given with a trailing
+   dot component. */
+#undef FUNC_MKDIR_DOT_BUG
+
 /* Define to 1 if realpath() can malloc memory, always gives an absolute path,
    and handles trailing slash correctly. */
 #undef FUNC_REALPATH_WORKS
diff --git a/gdb/gnulib/configure b/gdb/gnulib/configure
index a5d76ac..8c30276 100644
--- a/gdb/gnulib/configure
+++ b/gdb/gnulib/configure
@@ -5732,6 +5732,7 @@  fi
   # Code from module memmem-simple:
   # Code from module mempcpy:
   # Code from module memrchr:
+  # Code from module mkdir:
   # Code from module mkstemp:
   # Code from module msvc-inval:
   # Code from module msvc-nothrow:
@@ -20781,6 +20782,131 @@  $as_echo "#define GNULIB_TEST_MEMRCHR 1" >>confdefs.h
 
 
 
+  :
+
+
+
+
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether mkdir handles trailing slash" >&5
+$as_echo_n "checking whether mkdir handles trailing slash... " >&6; }
+if ${gl_cv_func_mkdir_trailing_slash_works+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  rm -rf conftest.dir
+      if test "$cross_compiling" = yes; then :
+  case "$host_os" in
+                 # Guess yes on glibc systems.
+         *-gnu*) gl_cv_func_mkdir_trailing_slash_works="guessing yes" ;;
+                 # If we don't know, assume the worst.
+         *)      gl_cv_func_mkdir_trailing_slash_works="guessing no" ;;
+       esac
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#       include <sys/types.h>
+#       include <sys/stat.h>
+
+int
+main ()
+{
+return mkdir ("conftest.dir/", 0700);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gl_cv_func_mkdir_trailing_slash_works=yes
+else
+  gl_cv_func_mkdir_trailing_slash_works=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+    rm -rf conftest.dir
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_mkdir_trailing_slash_works" >&5
+$as_echo "$gl_cv_func_mkdir_trailing_slash_works" >&6; }
+  case "$gl_cv_func_mkdir_trailing_slash_works" in
+    *yes) ;;
+    *)
+      REPLACE_MKDIR=1
+      ;;
+  esac
+
+  { $as_echo "$as_me:${as_lineno-$LINENO}: checking whether mkdir handles trailing dot" >&5
+$as_echo_n "checking whether mkdir handles trailing dot... " >&6; }
+if ${gl_cv_func_mkdir_trailing_dot_works+:} false; then :
+  $as_echo_n "(cached) " >&6
+else
+  rm -rf conftest.dir
+      if test "$cross_compiling" = yes; then :
+  case "$host_os" in
+                 # Guess yes on glibc systems.
+         *-gnu*) gl_cv_func_mkdir_trailing_dot_works="guessing yes" ;;
+                 # If we don't know, assume the worst.
+         *)      gl_cv_func_mkdir_trailing_dot_works="guessing no" ;;
+       esac
+
+else
+  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
+/* end confdefs.h.  */
+
+#       include <sys/types.h>
+#       include <sys/stat.h>
+
+int
+main ()
+{
+return !mkdir ("conftest.dir/./", 0700);
+  ;
+  return 0;
+}
+_ACEOF
+if ac_fn_c_try_run "$LINENO"; then :
+  gl_cv_func_mkdir_trailing_dot_works=yes
+else
+  gl_cv_func_mkdir_trailing_dot_works=no
+fi
+rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
+  conftest.$ac_objext conftest.beam conftest.$ac_ext
+fi
+
+    rm -rf conftest.dir
+
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $gl_cv_func_mkdir_trailing_dot_works" >&5
+$as_echo "$gl_cv_func_mkdir_trailing_dot_works" >&6; }
+  case "$gl_cv_func_mkdir_trailing_dot_works" in
+    *yes) ;;
+    *)
+      REPLACE_MKDIR=1
+
+$as_echo "#define FUNC_MKDIR_DOT_BUG 1" >>confdefs.h
+
+      ;;
+  esac
+
+  if test $REPLACE_MKDIR = 1; then
+
+
+
+
+
+
+
+
+  gl_LIBOBJS="$gl_LIBOBJS mkdir.$ac_objext"
+
+  fi
+
+
 
 
   :
diff --git a/gdb/gnulib/import/Makefile.am b/gdb/gnulib/import/Makefile.am
index 8409386..67acc9d 100644
--- a/gdb/gnulib/import/Makefile.am
+++ b/gdb/gnulib/import/Makefile.am
@@ -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 inttypes limits-h lstat memchr memmem mkstemp 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 inttypes limits-h lstat memchr memmem mkdir mkstemp 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
 
@@ -1169,6 +1169,15 @@  EXTRA_libgnu_a_SOURCES += memrchr.c
 
 ## end   gnulib module memrchr
 
+## begin gnulib module mkdir
+
+
+EXTRA_DIST += mkdir.c
+
+EXTRA_libgnu_a_SOURCES += mkdir.c
+
+## end   gnulib module mkdir
+
 ## begin gnulib module mkstemp
 
 
diff --git a/gdb/gnulib/import/Makefile.in b/gdb/gnulib/import/Makefile.in
index 8f00111..5c1a22b 100644
--- a/gdb/gnulib/import/Makefile.in
+++ b/gdb/gnulib/import/Makefile.in
@@ -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 inttypes limits-h lstat memchr memmem mkstemp 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 inttypes limits-h lstat memchr memmem mkdir mkstemp pathmax rawmemchr readlink rename setenv signal-h strchrnul strstr strtok_r sys_stat unistd unsetenv update-copyright wchar wctype-h
 
 
 
@@ -189,6 +189,7 @@  am__aclocal_m4_deps = $(top_srcdir)/import/m4/00gnulib.m4 \
 	$(top_srcdir)/import/m4/memmem.m4 \
 	$(top_srcdir)/import/m4/mempcpy.m4 \
 	$(top_srcdir)/import/m4/memrchr.m4 \
+	$(top_srcdir)/import/m4/mkdir.m4 \
 	$(top_srcdir)/import/m4/mkstemp.m4 \
 	$(top_srcdir)/import/m4/mmap-anon.m4 \
 	$(top_srcdir)/import/m4/mode_t.m4 \
@@ -1465,9 +1466,9 @@  EXTRA_DIST = m4/gnulib-cache.m4 alloca.c alloca.in.h assure.h \
 	lstat.c malloc.c malloca.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 mkstemp.c msvc-inval.c msvc-inval.h \
-	msvc-nothrow.c msvc-nothrow.h open.c openat.c openat.h \
-	dirent-private.h opendir.c pathmax.h rawmemchr.c \
+	mempcpy.c memrchr.c mkdir.c mkstemp.c msvc-inval.c \
+	msvc-inval.h msvc-nothrow.c msvc-nothrow.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 \
@@ -1533,9 +1534,9 @@  EXTRA_libgnu_a_SOURCES = alloca.c openat-proc.c canonicalize-lgpl.c \
 	fstatat.c getcwd.c getcwd-lgpl.c getdtablesize.c getlogin_r.c \
 	gettimeofday.c glob.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 mkstemp.c \
-	msvc-inval.c msvc-nothrow.c open.c openat.c opendir.c \
-	rawmemchr.c readdir.c readlink.c realloc.c rename.c \
+	mbsrtowcs.c memchr.c memmem.c mempcpy.c memrchr.c mkdir.c \
+	mkstemp.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
@@ -1667,6 +1668,7 @@  distclean-compile:
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/memmem.Po@am__quote@
 @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)/mkstemp.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@
diff --git a/gdb/gnulib/import/m4/gnulib-cache.m4 b/gdb/gnulib/import/m4/gnulib-cache.m4
index f65058f..225b52a 100644
--- a/gdb/gnulib/import/m4/gnulib-cache.m4
+++ b/gdb/gnulib/import/m4/gnulib-cache.m4
@@ -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 inttypes limits-h lstat memchr memmem mkstemp 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 inttypes limits-h lstat memchr memmem mkdir mkstemp 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([])
@@ -46,6 +46,7 @@  gl_MODULES([
   lstat
   memchr
   memmem
+  mkdir
   mkstemp
   pathmax
   rawmemchr
diff --git a/gdb/gnulib/import/m4/gnulib-comp.m4 b/gdb/gnulib/import/m4/gnulib-comp.m4
index c5a8092..6fee9ef 100644
--- a/gdb/gnulib/import/m4/gnulib-comp.m4
+++ b/gdb/gnulib/import/m4/gnulib-comp.m4
@@ -118,6 +118,7 @@  AC_DEFUN([gl_EARLY],
   # Code from module memmem-simple:
   # Code from module mempcpy:
   # Code from module memrchr:
+  # Code from module mkdir:
   # Code from module mkstemp:
   # Code from module msvc-inval:
   # Code from module msvc-nothrow:
@@ -424,6 +425,10 @@  AC_DEFUN([gl_INIT],
     gl_PREREQ_MEMRCHR
   fi
   gl_STRING_MODULE_INDICATOR([memrchr])
+  gl_FUNC_MKDIR
+  if test $REPLACE_MKDIR = 1; then
+    AC_LIBOBJ([mkdir])
+  fi
   gl_FUNC_MKSTEMP
   if test $HAVE_MKSTEMP = 0 || test $REPLACE_MKSTEMP = 1; then
     AC_LIBOBJ([mkstemp])
@@ -813,6 +818,7 @@  AC_DEFUN([gl_FILE_LIST], [
   lib/memmem.c
   lib/mempcpy.c
   lib/memrchr.c
+  lib/mkdir.c
   lib/mkstemp.c
   lib/msvc-inval.c
   lib/msvc-inval.h
@@ -952,6 +958,7 @@  AC_DEFUN([gl_FILE_LIST], [
   m4/memmem.m4
   m4/mempcpy.m4
   m4/memrchr.m4
+  m4/mkdir.m4
   m4/mkstemp.m4
   m4/mmap-anon.m4
   m4/mode_t.m4
diff --git a/gdb/gnulib/import/m4/mkdir.m4 b/gdb/gnulib/import/m4/mkdir.m4
new file mode 100644
index 0000000..574092b
--- /dev/null
+++ b/gdb/gnulib/import/m4/mkdir.m4
@@ -0,0 +1,69 @@ 
+# serial 11
+
+# Copyright (C) 2001, 2003-2004, 2006, 2008-2016 Free Software Foundation, Inc.
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# On some systems, mkdir ("foo/", 0700) fails because of the trailing slash.
+# On others, mkdir ("foo/./", 0700) mistakenly succeeds.
+# On such systems, arrange to use a wrapper function.
+AC_DEFUN([gl_FUNC_MKDIR],
+[dnl
+  AC_REQUIRE([gl_SYS_STAT_H_DEFAULTS])
+  AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
+  AC_CHECK_HEADERS_ONCE([unistd.h])
+  AC_CACHE_CHECK([whether mkdir handles trailing slash],
+    [gl_cv_func_mkdir_trailing_slash_works],
+    [rm -rf conftest.dir
+      AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#       include <sys/types.h>
+#       include <sys/stat.h>
+]], [return mkdir ("conftest.dir/", 0700);])],
+      [gl_cv_func_mkdir_trailing_slash_works=yes],
+      [gl_cv_func_mkdir_trailing_slash_works=no],
+      [case "$host_os" in
+                 # Guess yes on glibc systems.
+         *-gnu*) gl_cv_func_mkdir_trailing_slash_works="guessing yes" ;;
+                 # If we don't know, assume the worst.
+         *)      gl_cv_func_mkdir_trailing_slash_works="guessing no" ;;
+       esac
+      ])
+    rm -rf conftest.dir
+    ]
+  )
+  case "$gl_cv_func_mkdir_trailing_slash_works" in
+    *yes) ;;
+    *)
+      REPLACE_MKDIR=1
+      ;;
+  esac
+
+  AC_CACHE_CHECK([whether mkdir handles trailing dot],
+    [gl_cv_func_mkdir_trailing_dot_works],
+    [rm -rf conftest.dir
+      AC_RUN_IFELSE([AC_LANG_PROGRAM([[
+#       include <sys/types.h>
+#       include <sys/stat.h>
+]], [return !mkdir ("conftest.dir/./", 0700);])],
+      [gl_cv_func_mkdir_trailing_dot_works=yes],
+      [gl_cv_func_mkdir_trailing_dot_works=no],
+      [case "$host_os" in
+                 # Guess yes on glibc systems.
+         *-gnu*) gl_cv_func_mkdir_trailing_dot_works="guessing yes" ;;
+                 # If we don't know, assume the worst.
+         *)      gl_cv_func_mkdir_trailing_dot_works="guessing no" ;;
+       esac
+      ])
+    rm -rf conftest.dir
+    ]
+  )
+  case "$gl_cv_func_mkdir_trailing_dot_works" in
+    *yes) ;;
+    *)
+      REPLACE_MKDIR=1
+      AC_DEFINE([FUNC_MKDIR_DOT_BUG], [1], [Define to 1 if mkdir mistakenly
+        creates a directory given with a trailing dot component.])
+      ;;
+  esac
+])
diff --git a/gdb/gnulib/import/mkdir.c b/gdb/gnulib/import/mkdir.c
new file mode 100644
index 0000000..59bdea1
--- /dev/null
+++ b/gdb/gnulib/import/mkdir.c
@@ -0,0 +1,93 @@ 
+/* On some systems, mkdir ("foo/", 0700) fails because of the trailing
+   slash.  On those systems, this wrapper removes the trailing slash.
+
+   Copyright (C) 2001, 2003, 2006, 2008-2016 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 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/>.  */
+
+/* written by Jim Meyering */
+
+#include <config.h>
+
+/* Specification.  */
+#include <sys/stat.h>
+
+#include <errno.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "dirname.h"
+
+/* Disable the definition of mkdir to rpl_mkdir (from the <sys/stat.h>
+   substitute) in this file.  Otherwise, we'd get an endless recursion.  */
+#undef mkdir
+
+/* mingw's _mkdir() function has 1 argument, but we pass 2 arguments.
+   Additionally, it declares _mkdir (and depending on compile flags, an
+   alias mkdir), only in the nonstandard includes <direct.h> and <io.h>,
+   which are included in the <sys/stat.h> override.  */
+#if (defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__
+# define mkdir(name,mode) _mkdir (name)
+# define maybe_unused _GL_UNUSED
+#else
+# define maybe_unused /* empty */
+#endif
+
+/* This function is required at least for NetBSD 1.5.2.  */
+
+int
+rpl_mkdir (char const *dir, mode_t mode maybe_unused)
+{
+  int ret_val;
+  char *tmp_dir;
+  size_t len = strlen (dir);
+
+  if (len && dir[len - 1] == '/')
+    {
+      tmp_dir = strdup (dir);
+      if (!tmp_dir)
+        {
+          /* Rather than rely on strdup-posix, we set errno ourselves.  */
+          errno = ENOMEM;
+          return -1;
+        }
+      strip_trailing_slashes (tmp_dir);
+    }
+  else
+    {
+      tmp_dir = (char *) dir;
+    }
+#if FUNC_MKDIR_DOT_BUG
+  /* Additionally, cygwin 1.5 mistakenly creates a directory "d/./".  */
+  {
+    char *last = last_component (tmp_dir);
+    if (*last == '.' && (last[1] == '\0'
+                         || (last[1] == '.' && last[2] == '\0')))
+      {
+        struct stat st;
+        if (stat (tmp_dir, &st) == 0)
+          errno = EEXIST;
+        return -1;
+      }
+  }
+#endif /* FUNC_MKDIR_DOT_BUG */
+
+  ret_val = mkdir (tmp_dir, mode);
+
+  if (tmp_dir != dir)
+    free (tmp_dir);
+
+  return ret_val;
+}
diff --git a/gdb/gnulib/update-gnulib.sh b/gdb/gnulib/update-gnulib.sh
index bef4937..1c2ee4b 100755
--- a/gdb/gnulib/update-gnulib.sh
+++ b/gdb/gnulib/update-gnulib.sh
@@ -44,6 +44,7 @@  IMPORTED_GNULIB_MODULES="\
     limits-h \
     memchr \
     memmem \
+    mkdir \
     mkstemp \
     pathmax \
     rawmemchr \