summaryrefslogtreecommitdiff
path: root/gdb/unittests
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/unittests
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/unittests')
-rw-r--r--gdb/unittests/scoped_fd-selftests.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/gdb/unittests/scoped_fd-selftests.c b/gdb/unittests/scoped_fd-selftests.c
index fb6a0d675dd..6a9c727477d 100644
--- a/gdb/unittests/scoped_fd-selftests.c
+++ b/gdb/unittests/scoped_fd-selftests.c
@@ -65,12 +65,29 @@ test_release ()
SELF_CHECK (close (fd) == 0 || errno != EBADF);
}
+/* Test that the file descriptor can be converted to a FILE *. */
+static void
+test_to_file ()
+{
+ char filename[] = "scoped_fd-selftest-XXXXXX";
+
+ ::scoped_fd sfd (gdb_mkostemp_cloexec (filename));
+ SELF_CHECK (sfd.get () >= 0);
+
+ unlink (filename);
+
+ gdb_file_up file = sfd.to_file ("rw");
+ SELF_CHECK (file != nullptr);
+ SELF_CHECK (sfd.get () == -1);
+}
+
/* Run selftests. */
static void
run_tests ()
{
test_destroy ();
test_release ();
+ test_to_file ();
}
} /* namespace scoped_fd */