diff --git a/packages/base/any/onlp/src/onlplib/module/inc/onlplib/file.h b/packages/base/any/onlp/src/onlplib/module/inc/onlplib/file.h index 0394c5aa..85a6a105 100644 --- a/packages/base/any/onlp/src/onlplib/module/inc/onlplib/file.h +++ b/packages/base/any/onlp/src/onlplib/module/inc/onlplib/file.h @@ -98,6 +98,30 @@ int onlp_file_vread_str(char** str, const char* fmt, va_list vargs); */ int onlp_file_read_str(char** str, const char* fmt, ...); +/** + * @brief Read and place the contents of the given file into the + * given buffer. + * @param dst Destination buffer + * @param size Max size + * @param fmt The filename format string + * @param vargs The filename format args. + * @note The contents of the file are assume to be a string. + * Trailing newlines are removed. + */ +int onlp_file_vread_str_dst(char* dst, int size, const char* fmt, va_list vargs); + +/** + * @brief Read and place the contents of the given file into the + * given buffer. + * @param dst Destination buffer + * @param size Max size + * @param fmt The filename format string + * @param ... The filename format args. + * @note The contents of the file are assume to be a string. + * Trailing newlines are removed. + */ +int onlp_file_read_str_dst(char* dst, int size, const char* fmt, ...); + /** * @brief Read and return the integer contents of the given file. * @param value Receives the integer value. diff --git a/packages/base/any/onlp/src/onlplib/module/src/file.c b/packages/base/any/onlp/src/onlplib/module/src/file.c index 43e8618c..99f367d2 100644 --- a/packages/base/any/onlp/src/onlplib/module/src/file.c +++ b/packages/base/any/onlp/src/onlplib/module/src/file.c @@ -258,6 +258,27 @@ onlp_file_read_str(char** str, const char* fmt, ...) return rv; } +int +onlp_file_vread_str_dst(char* dst, int size, const char* fmt, va_list vargs) +{ + char* s; + ONLP_TRY(onlp_file_vread_str(&s, fmt, vargs)); + aim_strlcpy(dst, s, size); + aim_free(s); + return ONLP_STATUS_OK; +} + +int +onlp_file_read_str_dst(char* dst, int size, const char* fmt, ...) +{ + int rv; + va_list vargs; + va_start(vargs, fmt); + rv = onlp_file_vread_str_dst(dst, size, fmt, vargs); + va_end(vargs); + return rv; +} + int onlp_file_vread_int(int* value, const char* fmt, va_list vargs) {