qcacmn: Add qdf_str_dup() API
Add a QDF abstraction for strdup(). Change-Id: I141e625a91e3433c2a66bc75b4e860ed6ef266ac CRs-Fixed: 2194537
This commit is contained in:
@@ -40,6 +40,17 @@ static inline bool qdf_is_space(char c)
|
||||
return __qdf_is_space(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* qdf_str_dup() - duplicate null-terminated string @src
|
||||
* @dest: double pointer to be populated
|
||||
* @src: the null-terminated string to be duplicated
|
||||
*
|
||||
* @dest must be freed using qdf_mem_free() to avoid memory leaks.
|
||||
*
|
||||
* Return: QDF_STATUS; @dest set to NULL on failure, a valid address on success
|
||||
*/
|
||||
QDF_STATUS qdf_str_dup(char **dest, const char *src);
|
||||
|
||||
/**
|
||||
* qdf_str_left_trim() - Trim any leading whitespace from @str
|
||||
* @str: the string to trim
|
||||
|
@@ -19,6 +19,31 @@
|
||||
#include "qdf_mem.h"
|
||||
#include "qdf_module.h"
|
||||
#include "qdf_str.h"
|
||||
#include "qdf_trace.h"
|
||||
|
||||
QDF_STATUS qdf_str_dup(char **dest, const char *src)
|
||||
{
|
||||
qdf_size_t size;
|
||||
char *dup;
|
||||
|
||||
*dest = NULL;
|
||||
|
||||
QDF_BUG(src);
|
||||
if (!src)
|
||||
return QDF_STATUS_E_INVAL;
|
||||
|
||||
/* size = length + null-terminator */
|
||||
size = qdf_str_len(src) + 1;
|
||||
dup = qdf_mem_malloc(size);
|
||||
if (!dup)
|
||||
return QDF_STATUS_E_NOMEM;
|
||||
|
||||
qdf_mem_copy(dup, src, size);
|
||||
*dest = dup;
|
||||
|
||||
return QDF_STATUS_SUCCESS;
|
||||
}
|
||||
qdf_export_symbol(qdf_str_dup);
|
||||
|
||||
void qdf_str_right_trim(char *str)
|
||||
{
|
||||
|
Reference in New Issue
Block a user