aboutsummaryrefslogtreecommitdiff
path: root/gdb/source.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/source.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/source.c')
-rw-r--r--gdb/source.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/gdb/source.c b/gdb/source.c
index eec6e77..3559eea 100644
--- a/gdb/source.c
+++ b/gdb/source.c
@@ -832,7 +832,7 @@ openp (const char *path, openp_flags opts, const char *string,
{
filename = (char *) alloca (strlen (string) + 1);
strcpy (filename, string);
- fd = gdb_open_cloexec (filename, mode, 0);
+ fd = gdb_open_cloexec (filename, mode, 0).release ();
if (fd >= 0)
goto done;
last_errno = errno;
@@ -924,7 +924,7 @@ openp (const char *path, openp_flags opts, const char *string,
if (is_regular_file (filename, &reg_file_errno))
{
- fd = gdb_open_cloexec (filename, mode, 0);
+ fd = gdb_open_cloexec (filename, mode, 0).release ();
if (fd >= 0)
break;
last_errno = errno;
@@ -1060,7 +1060,6 @@ find_and_open_source (const char *filename,
{
char *path = source_path;
const char *p;
- int result;
/* If reading of source files is disabled then return a result indicating
the attempt to read this source file failed. GDB will then display
@@ -1080,12 +1079,11 @@ find_and_open_source (const char *filename,
if (rewritten_fullname != NULL)
*fullname = std::move (rewritten_fullname);
- result = gdb_open_cloexec (fullname->get (), OPEN_MODE, 0);
-
- if (result >= 0)
+ scoped_fd result = gdb_open_cloexec (fullname->get (), OPEN_MODE, 0);
+ if (result.get () >= 0)
{
*fullname = gdb_realpath (fullname->get ());
- return scoped_fd (result);
+ return result;
}
/* Didn't work -- free old one, try again. */
@@ -1129,8 +1127,8 @@ find_and_open_source (const char *filename,
filename = rewritten_filename.get ();
/* Try to locate file using filename. */
- result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, filename,
- OPEN_MODE, fullname);
+ int result = openp (path, OPF_SEARCH_IN_PATH | OPF_RETURN_REALPATH, filename,
+ OPEN_MODE, fullname);
if (result < 0 && dirname != NULL)
{
/* Remove characters from the start of PATH that we don't need when