Move gdb/warning.m4 to gdbsupport
[binutils-gdb.git] / gdb / unittests / mkdir-recursive-selftests.c
index d501f8e0817c1483888daadc9dc4ba2b61fb2dad..8647515e0625213b1912268b14ebada0e425bba1 100644 (file)
@@ -1,6 +1,6 @@
 /* Self tests for scoped_fd for GDB, the GNU debugger.
 
-   Copyright (C) 2018 Free Software Foundation, Inc.
+   Copyright (C) 2018-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
 
 #include "defs.h"
 
-#include "common/filestuff.h"
-#include "selftest.h"
+#include "gdbsupport/filestuff.h"
+#include "gdbsupport/selftest.h"
+#include "gdbsupport/byte-vector.h"
+#include "gdbsupport/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,24 +69,23 @@ 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 ()));
 }
 
 }
 }
 
+void _initialize_mkdir_recursive_selftests ();
 void
 _initialize_mkdir_recursive_selftests ()
 {
-#if defined (HAVE_MKDTEMP)
   selftests::register_test ("mkdir_recursive",
                            selftests::mkdir_recursive::test);
-#endif
 }