summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-25 20:42:45 +0200
committerDavid Oberhollenzer <david.oberhollenzer@sigma-star.at>2020-09-29 15:33:15 +0200
commitd87bffd89b9c0a26a65f0c629250fa87902b6cb8 (patch)
treef16931b1c7b53a8c687f5eb389e3584df3013e7a /include
parent897a625cacdd9201f9f2531f5ce97c4ab5e5d90a (diff)
Add a more usefull getline-like function to libfstream
Signed-off-by: David Oberhollenzer <david.oberhollenzer@sigma-star.at>
Diffstat (limited to 'include')
-rw-r--r--include/fstream.h35
1 files changed, 35 insertions, 0 deletions
diff --git a/include/fstream.h b/include/fstream.h
index 8693fff..07ee5a7 100644
--- a/include/fstream.h
+++ b/include/fstream.h
@@ -56,6 +56,12 @@ enum {
};
enum {
+ ISTREAM_LINE_LTRIM = 0x01,
+ ISTREAM_LINE_RTRIM = 0x02,
+ ISTREAM_LINE_SKIP_EMPTY = 0x04,
+};
+
+enum {
/**
* @brief Deflate compressor with gzip headers.
*
@@ -258,6 +264,35 @@ SQFS_INTERNAL const char *ostream_get_filename(ostream_t *strm);
SQFS_INTERNAL int ostream_printf(ostream_t *strm, const char *fmt, ...);
/**
+ * @brief Read a line of text from an input stream
+ *
+ * @memberof 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(istream_t *strm, char **out,
+ size_t *line_num, int flags);
+
+/**
* @brief Read data from an input stream
*
* @memberof istream_t