mirror of
https://github.com/Telecominfraproject/OpenNetworkLinux.git
synced 2025-12-25 17:27:01 +00:00
Add a version of read_str which reads to a buffer instead of returning a new one.
This commit is contained in:
@@ -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.
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user