summaryrefslogtreecommitdiffstats
path: root/tools/lib/api/io.h
diff options
context:
space:
mode:
Diffstat (limited to 'tools/lib/api/io.h')
-rw-r--r--tools/lib/api/io.h11
1 files changed, 8 insertions, 3 deletions
diff --git a/tools/lib/api/io.h b/tools/lib/api/io.h
index 2a7fe97588..84adf81020 100644
--- a/tools/lib/api/io.h
+++ b/tools/lib/api/io.h
@@ -141,8 +141,8 @@ static inline int io__get_dec(struct io *io, __u64 *dec)
}
}
-/* Read up to and including the first newline following the pattern of getline. */
-static inline ssize_t io__getline(struct io *io, char **line_out, size_t *line_len_out)
+/* Read up to and including the first delim. */
+static inline ssize_t io__getdelim(struct io *io, char **line_out, size_t *line_len_out, int delim)
{
char buf[128];
int buf_pos = 0;
@@ -152,7 +152,7 @@ static inline ssize_t io__getline(struct io *io, char **line_out, size_t *line_l
/* TODO: reuse previously allocated memory. */
free(*line_out);
- while (ch != '\n') {
+ while (ch != delim) {
ch = io__get_char(io);
if (ch < 0)
@@ -185,4 +185,9 @@ err_out:
return -ENOMEM;
}
+static inline ssize_t io__getline(struct io *io, char **line_out, size_t *line_len_out)
+{
+ return io__getdelim(io, line_out, line_len_out, /*delim=*/'\n');
+}
+
#endif /* __API_IO__ */