in UPDATE make in reading functions public
diff --git a/src/in.c b/src/in.c
index 033b642..431c10a 100644
--- a/src/in.c
+++ b/src/in.c
@@ -254,6 +254,8 @@
LIBYANG_API_DEF size_t
ly_in_parsed(const struct ly_in *in)
{
+ LY_CHECK_ARG_RET(NULL, in, 0);
+
return in->current - in->func_start;
}
@@ -295,9 +297,11 @@
free(in);
}
-LY_ERR
+LIBYANG_API_DEF LY_ERR
ly_in_read(struct ly_in *in, void *buf, size_t count)
{
+ LY_CHECK_ARG_RET(NULL, in, buf, LY_EINVAL);
+
if (in->length && (in->length - (in->current - in->start) < count)) {
/* EOF */
return LY_EDENIED;
@@ -310,9 +314,11 @@
return LY_SUCCESS;
}
-LY_ERR
+LIBYANG_API_DEF LY_ERR
ly_in_skip(struct ly_in *in, size_t count)
{
+ LY_CHECK_ARG_RET(NULL, in, LY_EINVAL);
+
if (in->length && (in->length - (in->current - in->start) < count)) {
/* EOF */
return LY_EDENIED;
diff --git a/src/in.h b/src/in.h
index cde70dd..62f5aae 100644
--- a/src/in.h
+++ b/src/in.h
@@ -211,12 +211,40 @@
/**
* @brief Free the input handler.
+ *
* @param[in] in Input handler to free.
* @param[in] destroy Flag to free the input data buffer (for LY_IN_MEMORY) or to
* close stream/file descriptor (for LY_IN_FD and LY_IN_FILE)
*/
LIBYANG_API_DECL void ly_in_free(struct ly_in *in, ly_bool destroy);
+/**
+ * @brief Read bytes from an input.
+ *
+ * Does not count new lines, which is expected from the caller who has better idea about
+ * the content of the read data and can better optimize counting.
+ *
+ * @param[in] in Input structure.
+ * @param[in] buf Destination buffer.
+ * @param[in] count Number of bytes to read.
+ * @return LY_SUCCESS on success,
+ * @return LY_EDENIED on EOF.
+ */
+LIBYANG_API_DECL LY_ERR ly_in_read(struct ly_in *in, void *buf, size_t count);
+
+/**
+ * @brief Just skip bytes in an input.
+ *
+ * Does not count new lines, which is expected from the caller who has better idea about
+ * the content of the skipped data and can better optimize counting.
+ *
+ * @param[in] in Input structure.
+ * @param[in] count Number of bytes to skip.
+ * @return LY_SUCCESS on success,
+ * @return LY_EDENIED on EOF.
+ */
+LIBYANG_API_DECL LY_ERR ly_in_skip(struct ly_in *in, size_t count);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/in_internal.h b/src/in_internal.h
index 02184d6..cbc56da 100644
--- a/src/in_internal.h
+++ b/src/in_internal.h
@@ -1,9 +1,10 @@
/**
* @file in_internal.h
* @author Radek Krejci <rkrejci@cesnet.cz>
+ * @author Michal Vasko <mvasko@cesnet.cz>
* @brief Internal structures and functions for libyang parsers
*
- * Copyright (c) 2020 CESNET, z.s.p.o.
+ * Copyright (c) 2020 - 2023 CESNET, z.s.p.o.
*
* This source code is licensed under BSD 3-Clause License (the "License").
* You may not use this file except in compliance with the License.
@@ -46,31 +47,4 @@
#define LY_IN_NEW_LINE(IN) \
(IN)->line++
-/**
- * @brief Read bytes from an input.
- *
- * Does not count new lines, which is expected from the caller who has better idea about
- * the content of the read data and can better optimize counting.
- *
- * @param[in] in Input structure.
- * @param[in] buf Destination buffer.
- * @param[in] count Number of bytes to read.
- * @return LY_SUCCESS on success,
- * @return LY_EDENIED on EOF.
- */
-LY_ERR ly_in_read(struct ly_in *in, void *buf, size_t count);
-
-/**
- * @brief Just skip bytes in an input.
- *
- * Does not count new lines, which is expected from the caller who has better idea about
- * the content of the skipped data and can better optimize counting.
- *
- * @param[in] in Input structure.
- * @param[in] count Number of bytes to skip.
- * @return LY_SUCCESS on success,
- * @return LY_EDENIED on EOF.
- */
-LY_ERR ly_in_skip(struct ly_in *in, size_t count);
-
#endif /* LY_IN_INTERNAL_H_ */