From ca9b6ba17257f88b8d575f18cab0b1e23660cfa5 Mon Sep 17 00:00:00 2001 From: David Oberhollenzer Date: Mon, 19 Jun 2023 18:57:38 +0200 Subject: Move istream_get_line function to libutil Signed-off-by: David Oberhollenzer --- include/fstree.h | 1 - include/io/dir_iterator.h | 2 +- include/io/istream.h | 55 ----------------------------------------------- include/io/mem.h | 2 +- include/io/std.h | 2 +- include/io/xfrm.h | 2 +- include/tar/tar.h | 1 - include/util/parse.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 59 insertions(+), 61 deletions(-) delete mode 100644 include/io/istream.h create mode 100644 include/util/parse.h (limited to 'include') diff --git a/include/fstree.h b/include/fstree.h index 779cd28..3c3782e 100644 --- a/include/fstree.h +++ b/include/fstree.h @@ -16,7 +16,6 @@ #include "sqfs/predef.h" #include "io/dir_entry.h" -#include "io/istream.h" #include "compat.h" typedef struct fstree_defaults_t fstree_defaults_t; diff --git a/include/io/dir_iterator.h b/include/io/dir_iterator.h index 152eb93..1ea3321 100644 --- a/include/io/dir_iterator.h +++ b/include/io/dir_iterator.h @@ -8,7 +8,7 @@ #define IO_DIR_ITERATOR_H #include "io/dir_entry.h" -#include "io/istream.h" +#include "sqfs/predef.h" /** * @interface dir_iterator_t diff --git a/include/io/istream.h b/include/io/istream.h deleted file mode 100644 index f41be2e..0000000 --- a/include/io/istream.h +++ /dev/null @@ -1,55 +0,0 @@ -/* SPDX-License-Identifier: GPL-3.0-or-later */ -/* - * istream.h - * - * Copyright (C) 2019 David Oberhollenzer - */ -#ifndef IO_ISTREAM_H -#define IO_ISTREAM_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 /* IO_ISTREAM_H */ diff --git a/include/io/mem.h b/include/io/mem.h index c848ef0..20b04ab 100644 --- a/include/io/mem.h +++ b/include/io/mem.h @@ -7,7 +7,7 @@ #ifndef IO_MEM_STREAM_H #define IO_MEM_STREAM_H -#include "io/istream.h" +#include "sqfs/predef.h" #ifdef __cplusplus extern "C" { diff --git a/include/io/std.h b/include/io/std.h index c5dddfa..a9f436a 100644 --- a/include/io/std.h +++ b/include/io/std.h @@ -7,7 +7,7 @@ #ifndef IO_STD_H #define IO_STD_H -#include "io/istream.h" +#include "sqfs/io.h" #ifdef __cplusplus extern "C" { diff --git a/include/io/xfrm.h b/include/io/xfrm.h index f0ff1ce..21ffa57 100644 --- a/include/io/xfrm.h +++ b/include/io/xfrm.h @@ -7,7 +7,7 @@ #ifndef IO_XFRM_H #define IO_XFRM_H -#include "io/istream.h" +#include "sqfs/predef.h" #include "xfrm/stream.h" #ifdef __cplusplus diff --git a/include/tar/tar.h b/include/tar/tar.h index 1f1b1b4..52a0562 100644 --- a/include/tar/tar.h +++ b/include/tar/tar.h @@ -9,7 +9,6 @@ #include "config.h" #include "compat.h" -#include "io/istream.h" #include "io/dir_iterator.h" #include "sqfs/io.h" 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 + */ +#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 */ -- cgit v1.2.3