aboutsummaryrefslogtreecommitdiff
path: root/gdb/auxv.c
diff options
context:
space:
mode:
authorSimon Marchi <simon.marchi@polymtl.ca>2021-07-22 11:56:33 -0400
committerSimon Marchi <simon.marchi@polymtl.ca>2021-09-30 15:21:48 -0400
commit13084383e8955c2ff7017ac8839301688a9ee34d (patch)
treeffc4d5429e7315de53715fe7fce7bd26abd958b8 /gdb/auxv.c
parente6e51c9c4b402cd46595790b26087ebf2fead8c1 (diff)
downloadgdb-13084383e8955c2ff7017ac8839301688a9ee34d.zip
gdb-13084383e8955c2ff7017ac8839301688a9ee34d.tar.gz
gdb-13084383e8955c2ff7017ac8839301688a9ee34d.tar.bz2
gdbsupport: make gdb_open_cloexec return scoped_fd
Make gdb_open_cloexec return a scoped_fd, to encourage using automatic management of the file descriptor closing. Except in the most trivial cases, I changed the callers to just release the fd, which retains their existing behavior. That will allow the transition to using scoped_fd more to go gradually, one caller at a time. Change-Id: Ife022b403f96e71d5ebb4f1056ef6251b30fe554
Diffstat (limited to 'gdb/auxv.c')
-rw-r--r--gdb/auxv.c14
1 files changed, 6 insertions, 8 deletions
diff --git a/gdb/auxv.c b/gdb/auxv.c
index 2bcf9f4..120e5c7 100644
--- a/gdb/auxv.c
+++ b/gdb/auxv.c
@@ -46,23 +46,21 @@ procfs_xfer_auxv (gdb_byte *readbuf,
ULONGEST len,
ULONGEST *xfered_len)
{
- int fd;
ssize_t l;
std::string pathname = string_printf ("/proc/%d/auxv", inferior_ptid.pid ());
- fd = gdb_open_cloexec (pathname, writebuf != NULL ? O_WRONLY : O_RDONLY, 0);
- if (fd < 0)
+ scoped_fd fd
+ = gdb_open_cloexec (pathname, writebuf != NULL ? O_WRONLY : O_RDONLY, 0);
+ if (fd.get () < 0)
return TARGET_XFER_E_IO;
if (offset != (ULONGEST) 0
- && lseek (fd, (off_t) offset, SEEK_SET) != (off_t) offset)
+ && lseek (fd.get (), (off_t) offset, SEEK_SET) != (off_t) offset)
l = -1;
else if (readbuf != NULL)
- l = read (fd, readbuf, (size_t) len);
+ l = read (fd.get (), readbuf, (size_t) len);
else
- l = write (fd, writebuf, (size_t) len);
-
- (void) close (fd);
+ l = write (fd.get (), writebuf, (size_t) len);
if (l < 0)
return TARGET_XFER_E_IO;