aboutsummaryrefslogtreecommitdiff
path: root/gdb/unittests
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-07-22 15:33:42 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-09-30 15:21:48 -0400
commit2fed9db40b1179f62c6fb0f2cacfb0db6b50af46 (patch)
treed47c517c106ec8bc88b6733d2b26f54f50dfec7c /gdb/unittests
parent13084383e8955c2ff7017ac8839301688a9ee34d (diff)
downloadgdb-2fed9db40b1179f62c6fb0f2cacfb0db6b50af46.zip
gdb-2fed9db40b1179f62c6fb0f2cacfb0db6b50af46.tar.gz
gdb-2fed9db40b1179f62c6fb0f2cacfb0db6b50af46.tar.bz2
gdbsupport: make gdb_mkostemp_cloexec return a scoped_fd
This encourages the callers to use automatic file descriptor management. Change-Id: I137a81df6f3607b457e28c35aafde8ed6f3a3344
Diffstat (limited to 'gdb/unittests')
-rw-r--r--gdb/unittests/scoped_fd-selftests.c6
-rw-r--r--gdb/unittests/scoped_mmap-selftests.c9
2 files changed, 8 insertions, 7 deletions
diff --git a/gdb/unittests/scoped_fd-selftests.c b/gdb/unittests/scoped_fd-selftests.c
index d1803aa..ff8d093 100644
--- a/gdb/unittests/scoped_fd-selftests.c
+++ b/gdb/unittests/scoped_fd-selftests.c
@@ -32,7 +32,7 @@ static void
test_destroy ()
{
char filename[] = "scoped_fd-selftest-XXXXXX";
- int fd = gdb_mkostemp_cloexec (filename);
+ int fd = gdb_mkostemp_cloexec (filename).release ();
SELF_CHECK (fd >= 0);
unlink (filename);
@@ -51,7 +51,7 @@ static void
test_release ()
{
char filename[] = "scoped_fd-selftest-XXXXXX";
- int fd = gdb_mkostemp_cloexec (filename);
+ int fd = gdb_mkostemp_cloexec (filename).release ();
SELF_CHECK (fd >= 0);
unlink (filename);
@@ -71,7 +71,7 @@ test_to_file ()
{
char filename[] = "scoped_fd-selftest-XXXXXX";
- ::scoped_fd sfd (gdb_mkostemp_cloexec (filename));
+ ::scoped_fd sfd = gdb_mkostemp_cloexec (filename);
SELF_CHECK (sfd.get () >= 0);
unlink (filename);
diff --git a/gdb/unittests/scoped_mmap-selftests.c b/gdb/unittests/scoped_mmap-selftests.c
index 92a821d..76d6c41 100644
--- a/gdb/unittests/scoped_mmap-selftests.c
+++ b/gdb/unittests/scoped_mmap-selftests.c
@@ -89,11 +89,12 @@ static void
test_normal ()
{
char filename[] = "scoped_mmapped_file-selftest-XXXXXX";
- int fd = gdb_mkostemp_cloexec (filename);
- SELF_CHECK (fd >= 0);
+ {
+ scoped_fd fd = gdb_mkostemp_cloexec (filename);
+ SELF_CHECK (fd.get () >= 0);
- SELF_CHECK (write (fd, "Hello!", 7) == 7);
- close (fd);
+ SELF_CHECK (write (fd.get (), "Hello!", 7) == 7);
+ }
gdb::unlinker unlink_test_file (filename);