Move make_temp_filename to common/pathstuff.c
authorTom Tromey <tom@tromey.com>
Fri, 14 Sep 2018 17:28:45 +0000 (11:28 -0600)
committerTom Tromey <tom@tromey.com>
Sat, 27 Oct 2018 17:58:40 +0000 (11:58 -0600)
Currently make_temp_filename is a function local to
write_psymtabs_to_index.  This patch moves it to pathstuff.c so that
it can be used from other places in gdb.

gdb/ChangeLog
2018-10-27  Tom Tromey  <tom@tromey.com>

* dwarf-index-write.c (write_psymtabs_to_index): Move
make_temp_filename to common/pathstuff.c.
* common/pathstuff.h (make_temp_filename): Declare.
* common/pathstuff.c (make_temp_filename): New function, moved
from dwarf-index-write.c.

gdb/ChangeLog
gdb/common/pathstuff.c
gdb/common/pathstuff.h
gdb/dwarf-index-write.c

index 5c5c8b12a6bb99c9cc8f4e7de27254549bff5cb8..b9ffa69451b3896925962f5f318bc6deb8c8a6aa 100644 (file)
@@ -1,3 +1,11 @@
+2018-10-27  Tom Tromey  <tom@tromey.com>
+
+       * dwarf-index-write.c (write_psymtabs_to_index): Move
+       make_temp_filename to common/pathstuff.c.
+       * common/pathstuff.h (make_temp_filename): Declare.
+       * common/pathstuff.c (make_temp_filename): New function, moved
+       from dwarf-index-write.c.
+
 2018-10-27  Tom Tromey  <tom@tromey.com>
 
        * procfs.c (procfs_target::create_inferior): Use get_shell.
index 6d8e53f4e1b124c8027ab4280b26e0b4144aad9d..48ff861edaed82f81b99e8248d41352a86fb4260 100644 (file)
@@ -202,3 +202,14 @@ get_shell ()
 
   return ret;
 }
+
+/* See common/pathstuff.h.  */
+
+gdb::char_vector
+make_temp_filename (const std::string &f)
+{
+  gdb::char_vector filename_temp (f.length () + 8);
+  strcpy (filename_temp.data (), f.c_str ());
+  strcat (filename_temp.data () + f.size (), "-XXXXXX");
+  return filename_temp;
+}
index 0a8caeacba773cf1874e8357f73869f43063c8a5..d57aafff0794d4e764022bfcd829fee8a3775477 100644 (file)
@@ -20,6 +20,8 @@
 #ifndef PATHSTUFF_H
 #define PATHSTUFF_H
 
+#include "common/byte-vector.h"
+
 /* Path utilities.  */
 
 /* Return the real path of FILENAME, expanding all the symbolic links.
@@ -69,4 +71,9 @@ extern std::string get_standard_cache_dir ();
 
 extern const char *get_shell ();
 
+/* Make a filename suitable to pass to mkstemp based on F (e.g.
+   /tmp/foo -> /tmp/foo-XXXXXX).  */
+
+extern gdb::char_vector make_temp_filename (const std::string &f);
+
 #endif /* PATHSTUFF_H */
index d4585af837cd080ede9fcff4ef0def0d6a9d6a9e..4335c39074fec1bc908dcedc9e76f9cf19812dba 100644 (file)
@@ -24,6 +24,7 @@
 #include "common/byte-vector.h"
 #include "common/filestuff.h"
 #include "common/gdb_unlinker.h"
+#include "common/pathstuff.h"
 #include "common/scoped_fd.h"
 #include "complaints.h"
 #include "dwarf-index-common.h"
@@ -1560,16 +1561,6 @@ write_psymtabs_to_index (struct dwarf2_per_objfile *dwarf2_per_objfile,
   if (stat (objfile_name (objfile), &st) < 0)
     perror_with_name (objfile_name (objfile));
 
-  /* Make a filename suitable to pass to mkstemp based on F (e.g.
-     /tmp/foo -> /tmp/foo-XXXXXX).  */
-  auto make_temp_filename = [] (const std::string &f) -> gdb::char_vector
-    {
-      gdb::char_vector filename_temp (f.length () + 8);
-      strcpy (filename_temp.data (), f.c_str ());
-      strcat (filename_temp.data () + f.size (), "-XXXXXX");
-      return filename_temp;
-    };
-
   std::string filename (std::string (dir) + SLASH_STRING + basename
                        + (index_kind == dw_index_kind::DEBUG_NAMES
                           ? INDEX5_SUFFIX : INDEX4_SUFFIX));