diff options
author | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-19 18:57:38 +0200 |
---|---|---|
committer | David Oberhollenzer <david.oberhollenzer@sigma-star.at> | 2023-06-20 10:57:38 +0200 |
commit | ca9b6ba17257f88b8d575f18cab0b1e23660cfa5 (patch) | |
tree | 355d8dbedb496f0235b08aba1bb73e41ba4083ba /include/util | |
parent | cb5473418b1f3b26555e26840a87a6feed3f583b (diff) |
Move istream_get_line function to libutil
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include/util')
-rw-r--r-- | include/util/parse.h | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/include/util/parse.h b/include/util/parse.h new file mode 100644 index 0000000..bc635ad --- /dev/null +++ b/include/util/parse.h @@ -0,0 +1,55 @@ +/* SPDX-License-Identifier: LGPL-3.0-or-later */ +/* + * parse.h + * + * Copyright (C) 2019 David Oberhollenzer <goliath@infraroot.at> + */ +#ifndef UTIL_PARSE_H +#define UTIL_PARSE_H + +#include "sqfs/predef.h" + +enum { + ISTREAM_LINE_LTRIM = 0x01, + ISTREAM_LINE_RTRIM = 0x02, + ISTREAM_LINE_SKIP_EMPTY = 0x04, +}; + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Read a line of text from an input stream + * + * @memberof sqfs_istream_t + * + * The line returned is allocated using malloc and must subsequently be + * freed when it is no longer needed. The line itself is always null-terminated + * and never includes the line break characters (LF or CR-LF). + * + * If the flag @ref ISTREAM_LINE_LTRIM is set, leading white space characters + * are removed. If the flag @ref ISTREAM_LINE_RTRIM is set, trailing white space + * characters are remvoed. + * + * If the flag @ref ISTREAM_LINE_SKIP_EMPTY is set and a line is discovered to + * be empty (after the optional trimming), the function discards the empty line + * and retries. The given line_num pointer is used to increment the line + * number. + * + * @param strm A pointer to an input stream. + * @param out Returns a pointer to a line on success. + * @param line_num This is incremented if lines are skipped. + * @param flags A combination of flags controling the functions behaviour. + * + * @return Zero on success, a negative value on error, a positive value if + * end-of-file was reached without reading any data. + */ +SQFS_INTERNAL int istream_get_line(sqfs_istream_t *strm, char **out, + size_t *line_num, int flags); + +#ifdef __cplusplus +} +#endif + +#endif /* UTIL_PARSE_H */ |