Skip to content

Commit 62c3726

Browse files
committed
in UPDATE make in reading functions public
1 parent 824861c commit 62c3726

File tree

3 files changed

+38
-30
lines changed

3 files changed

+38
-30
lines changed

src/in.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ ly_in_filepath(struct ly_in *in, const char *filepath, size_t len)
254254
LIBYANG_API_DEF size_t
255255
ly_in_parsed(const struct ly_in *in)
256256
{
257+
LY_CHECK_ARG_RET(NULL, in, 0);
258+
257259
return in->current - in->func_start;
258260
}
259261

@@ -295,9 +297,11 @@ ly_in_free(struct ly_in *in, ly_bool destroy)
295297
free(in);
296298
}
297299

298-
LY_ERR
300+
LIBYANG_API_DEF LY_ERR
299301
ly_in_read(struct ly_in *in, void *buf, size_t count)
300302
{
303+
LY_CHECK_ARG_RET(NULL, in, buf, LY_EINVAL);
304+
301305
if (in->length && (in->length - (in->current - in->start) < count)) {
302306
/* EOF */
303307
return LY_EDENIED;
@@ -310,9 +314,11 @@ ly_in_read(struct ly_in *in, void *buf, size_t count)
310314
return LY_SUCCESS;
311315
}
312316

313-
LY_ERR
317+
LIBYANG_API_DEF LY_ERR
314318
ly_in_skip(struct ly_in *in, size_t count)
315319
{
320+
LY_CHECK_ARG_RET(NULL, in, LY_EINVAL);
321+
316322
if (in->length && (in->length - (in->current - in->start) < count)) {
317323
/* EOF */
318324
return LY_EDENIED;

src/in.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,40 @@ LIBYANG_API_DECL size_t ly_in_parsed(const struct ly_in *in);
211211

212212
/**
213213
* @brief Free the input handler.
214+
*
214215
* @param[in] in Input handler to free.
215216
* @param[in] destroy Flag to free the input data buffer (for LY_IN_MEMORY) or to
216217
* close stream/file descriptor (for LY_IN_FD and LY_IN_FILE)
217218
*/
218219
LIBYANG_API_DECL void ly_in_free(struct ly_in *in, ly_bool destroy);
219220

221+
/**
222+
* @brief Read bytes from an input.
223+
*
224+
* Does not count new lines, which is expected from the caller who has better idea about
225+
* the content of the read data and can better optimize counting.
226+
*
227+
* @param[in] in Input structure.
228+
* @param[in] buf Destination buffer.
229+
* @param[in] count Number of bytes to read.
230+
* @return LY_SUCCESS on success,
231+
* @return LY_EDENIED on EOF.
232+
*/
233+
LIBYANG_API_DECL LY_ERR ly_in_read(struct ly_in *in, void *buf, size_t count);
234+
235+
/**
236+
* @brief Just skip bytes in an input.
237+
*
238+
* Does not count new lines, which is expected from the caller who has better idea about
239+
* the content of the skipped data and can better optimize counting.
240+
*
241+
* @param[in] in Input structure.
242+
* @param[in] count Number of bytes to skip.
243+
* @return LY_SUCCESS on success,
244+
* @return LY_EDENIED on EOF.
245+
*/
246+
LIBYANG_API_DECL LY_ERR ly_in_skip(struct ly_in *in, size_t count);
247+
220248
#ifdef __cplusplus
221249
}
222250
#endif

src/in_internal.h

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
/**
22
* @file in_internal.h
33
* @author Radek Krejci <[email protected]>
4+
* @author Michal Vasko <[email protected]>
45
* @brief Internal structures and functions for libyang parsers
56
*
6-
* Copyright (c) 2020 CESNET, z.s.p.o.
7+
* Copyright (c) 2020 - 2023 CESNET, z.s.p.o.
78
*
89
* This source code is licensed under BSD 3-Clause License (the "License").
910
* You may not use this file except in compliance with the License.
@@ -46,31 +47,4 @@ struct ly_in {
4647
#define LY_IN_NEW_LINE(IN) \
4748
(IN)->line++
4849

49-
/**
50-
* @brief Read bytes from an input.
51-
*
52-
* Does not count new lines, which is expected from the caller who has better idea about
53-
* the content of the read data and can better optimize counting.
54-
*
55-
* @param[in] in Input structure.
56-
* @param[in] buf Destination buffer.
57-
* @param[in] count Number of bytes to read.
58-
* @return LY_SUCCESS on success,
59-
* @return LY_EDENIED on EOF.
60-
*/
61-
LY_ERR ly_in_read(struct ly_in *in, void *buf, size_t count);
62-
63-
/**
64-
* @brief Just skip bytes in an input.
65-
*
66-
* Does not count new lines, which is expected from the caller who has better idea about
67-
* the content of the skipped data and can better optimize counting.
68-
*
69-
* @param[in] in Input structure.
70-
* @param[in] count Number of bytes to skip.
71-
* @return LY_SUCCESS on success,
72-
* @return LY_EDENIED on EOF.
73-
*/
74-
LY_ERR ly_in_skip(struct ly_in *in, size_t count);
75-
7650
#endif /* LY_IN_INTERNAL_H_ */

0 commit comments

Comments
 (0)