diff options
author | 2022-11-04 09:39:12 -0400 | |
---|---|---|
committer | 2022-11-08 16:50:52 -0500 | |
commit | 7a283d9cf5ccf26321f33812e79cf1515288ac94 (patch) | |
tree | 4518bf729385a5de34be59da6c2a223028fcb205 /gdbsupport/filestuff.h | |
parent | PowerPC: Add XSP operand define (diff) | |
download | binutils-gdb-7a283d9cf5ccf26321f33812e79cf1515288ac94.tar.gz binutils-gdb-7a283d9cf5ccf26321f33812e79cf1515288ac94.tar.bz2 binutils-gdb-7a283d9cf5ccf26321f33812e79cf1515288ac94.zip |
gdbsupport, gdb: add read_text_file_to_string, use it in linux_common_core_of_thread
I would like to add more code to nat/linux-osdata.c that reads an entire
file from /proc or /sys and processes it as a string afterwards. I
would like to avoid duplicating the somewhat error-prone code that reads
an entire file to a buffer. I think we should have a utility function
that does that.
Add read_file_to_string to gdbsupport/filestuff.{c,h}, and make
linux_common_core_of_thread use it. I want to make the new function
return an std::string, and because strtok doesn't play well with
std::string (it requires a `char *`, std::string::c_str returns a `const
char *`), change linux_common_core_of_thread to use std::string methods
instead.
Approved-By: Tom Tromey <tom@tromey.com>
Change-Id: I1793fda72a82969c28b944a84acb953f74c9230a
Diffstat (limited to 'gdbsupport/filestuff.h')
-rw-r--r-- | gdbsupport/filestuff.h | 4 |
1 files changed, 4 insertions, 0 deletions
diff --git a/gdbsupport/filestuff.h b/gdbsupport/filestuff.h index 4bc9249dcbf..33362901ab8 100644 --- a/gdbsupport/filestuff.h +++ b/gdbsupport/filestuff.h @@ -129,4 +129,8 @@ extern bool is_regular_file (const char *name, int *errno_ptr); extern bool mkdir_recursive (const char *dir); +/* Read the entire content of file PATH into an std::string. */ + +extern gdb::optional<std::string> read_text_file_to_string (const char *path); + #endif /* COMMON_FILESTUFF_H */ |