summaryrefslogtreecommitdiff
path: root/gdb/common
diff options
context:
space:
mode:
authorTom Tromey <tom@tromey.com>2018-09-20 16:30:47 -0600
committerTom Tromey <tom@tromey.com>2018-10-27 11:58:41 -0600
commit36033ef57cd048588f9a3d5523712147066421f2 (patch)
treec5e9a94e4f5eb6b7c4bd50fe3baf53cd52eee73f /gdb/common
parentb3279b601e67ce47263082ef86cfc86e25607c5e (diff)
downloadbinutils-gdb-36033ef57cd048588f9a3d5523712147066421f2.tar.gz
Do not reopen temporary files
The current callers of mkostemp close the file descriptor and then re-open it with fopen. It seemed better to me to continue to use the already-opened file descriptor, so this patch rearranges the code a little in order to do so. It takes care to ensure that the files are only unlinked after the file descriptor in question is closed, as before. gdb/ChangeLog 2018-10-27 Tom Tromey <tom@tromey.com> * unittests/scoped_fd-selftests.c (test_to_file): New function. (run_tests): Call test_to_file. * dwarf-index-write.c (write_psymtabs_to_index): Do not reopen temporary files. * common/scoped_fd.h (scoped_fd::to_file): New method.
Diffstat (limited to 'gdb/common')
-rw-r--r--gdb/common/scoped_fd.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/gdb/common/scoped_fd.h b/gdb/common/scoped_fd.h
index c2125bd1afe..d20e18a2c09 100644
--- a/gdb/common/scoped_fd.h
+++ b/gdb/common/scoped_fd.h
@@ -21,6 +21,7 @@
#define SCOPED_FD_H
#include <unistd.h>
+#include "filestuff.h"
/* A smart-pointer-like class to automatically close a file descriptor. */
@@ -43,6 +44,18 @@ public:
return fd;
}
+ /* Like release, but return a gdb_file_up that owns the file
+ descriptor. On success, this scoped_fd will be released. On
+ failure, return NULL and leave this scoped_fd in possession of
+ the fd. */
+ gdb_file_up to_file (const char *mode) noexcept
+ {
+ gdb_file_up result (fdopen (m_fd, mode));
+ if (result != nullptr)
+ m_fd = -1;
+ return result;
+ }
+
int get () const noexcept
{
return m_fd;