diff options
author | Tom Tromey <tom@tromey.com> | 2018-09-20 16:30:47 -0600 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2018-10-27 11:58:41 -0600 |
commit | 36033ef57cd048588f9a3d5523712147066421f2 (patch) | |
tree | c5e9a94e4f5eb6b7c4bd50fe3baf53cd52eee73f /gdb/unittests | |
parent | b3279b601e67ce47263082ef86cfc86e25607c5e (diff) | |
download | gdb-36033ef57cd048588f9a3d5523712147066421f2.zip gdb-36033ef57cd048588f9a3d5523712147066421f2.tar.gz gdb-36033ef57cd048588f9a3d5523712147066421f2.tar.bz2 |
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.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/gdb/unittests/scoped_fd-selftests.c b/gdb/unittests/scoped_fd-selftests.c index fb6a0d6..6a9c727 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 */ |