diff --git a/qdf/inc/qdf_mem.h b/qdf/inc/qdf_mem.h index 2c610ed976..2f36312394 100644 --- a/qdf/inc/qdf_mem.h +++ b/qdf/inc/qdf_mem.h @@ -34,6 +34,7 @@ #define __QDF_MEMORY_H /* Include Files */ +#include "qdf_str.h" /* TODO: update references and remove */ #include #include @@ -262,45 +263,6 @@ static inline int32_t qdf_mem_cmp(const void *memory1, const void *memory2, return __qdf_mem_cmp(memory1, memory2, num_bytes); } -/** - * qdf_str_cmp - Compare two strings - * @str1: First string - * @str2: Second string - * Return: =0 equal - * >0 not equal, if str1 sorts lexicographically after str2 - * <0 not equal, if str1 sorts lexicographically before str2 - */ -static inline int32_t qdf_str_cmp(const char *str1, const char *str2) -{ - return __qdf_str_cmp(str1, str2); -} - -/** - * qdf_str_eq - compare two null-terminated strings for equality - * @left: the string left of the equality - * @right: the string right of the equality - * - * This is a thin wrapper over `if (strcmp(left, right) == 0)` for clarity. - * - * Return: true if strings are equal - */ -static inline bool qdf_str_eq(const char *left, const char *right) -{ - return qdf_str_cmp(left, right) == 0; -} - -/** - * qdf_str_lcopy - Copy from one string to another - * @dest: destination string - * @src: source string - * @bytes: limit of num bytes to copy - * Return: =0 returns the initial value of dest - */ -static inline uint32_t qdf_str_lcopy(char *dest, const char *src, uint32_t bytes) -{ - return __qdf_str_lcopy(dest, src, bytes); -} - /** * qdf_mem_map_nbytes_single - Map memory for DMA * @osdev: pomter OS device context @@ -402,16 +364,6 @@ void qdf_mem_dma_sync_single_for_cpu(qdf_device_t osdev, qdf_dma_addr_t bus_addr, qdf_size_t size, __dma_data_direction direction); -/** - * qdf_str_len() - returns the length of a string - * @str: input string - * Return: - * length of string - */ -static inline int32_t qdf_str_len(const char *str) -{ - return __qdf_str_len(str); -} void qdf_mem_multi_pages_alloc(qdf_device_t osdev, struct qdf_mem_multi_page_t *pages, diff --git a/qdf/inc/qdf_str.h b/qdf/inc/qdf_str.h index 5b94c10f2b..7864a4412e 100644 --- a/qdf/inc/qdf_str.h +++ b/qdf/inc/qdf_str.h @@ -40,6 +40,20 @@ static inline bool qdf_is_space(char c) return __qdf_is_space(c); } +/** + * qdf_str_cmp - Compare two strings + * @str1: First string + * @str2: Second string + * Return: + * 0 - strings are equal + * <0 - str1 sorts lexicographically before str2 + * >0 - str1 sorts lexicographically after str2 + */ +static inline int32_t qdf_str_cmp(const char *str1, const char *str2) +{ + return __qdf_str_cmp(str1, str2); +} + /** * qdf_str_dup() - duplicate null-terminated string @src * @dest: double pointer to be populated @@ -51,6 +65,36 @@ static inline bool qdf_is_space(char c) */ QDF_STATUS qdf_str_dup(char **dest, const char *src); +/** + * qdf_str_eq - compare two null-terminated strings for equality + * @left: the string left of the equality + * @right: the string right of the equality + * + * This is a thin wrapper over `if (strcmp(left, right) == 0)` for clarity. + * + * Return: true if strings are equal + */ +static inline bool qdf_str_eq(const char *left, const char *right) +{ + return qdf_str_cmp(left, right) == 0; +} + +/** + * qdf_str_lcopy - Bounded copy from one string to another + * @dest: destination string + * @src: source string + * @dest_size: max number of bytes to copy (incl. null terminator) + * + * If the return value is >= @dest_size, @dest has been truncated. + * + * Return: length of @src + */ +static inline qdf_size_t +qdf_str_lcopy(char *dest, const char *src, uint32_t dest_size) +{ + return __qdf_str_lcopy(dest, src, dest_size); +} + /** * qdf_str_left_trim() - Trim any leading whitespace from @str * @str: the string to trim @@ -62,6 +106,17 @@ static inline const char *qdf_str_left_trim(const char *str) return __qdf_str_left_trim(str); } +/** + * qdf_str_len() - returns the length of a null-terminated string + * @str: input string + * + * Return: length of @str (without null terminator) + */ +static inline qdf_size_t qdf_str_len(const char *str) +{ + return __qdf_str_len(str); +} + /** * qdf_str_right_trim() - Trim any trailing whitespace from @str * @str: the string to trim @@ -92,9 +147,9 @@ static inline char *qdf_str_trim(char *str) * @str: the string to get the length of * @limit: the maximum number of characters to check * - * Return: length of @str, or @limit if the end is not found + * Return: the less of @limit or the length of @str (without null terminator) */ -static inline qdf_size_t qdf_str_nlen(const char *str, size_t limit) +static inline qdf_size_t qdf_str_nlen(const char *str, qdf_size_t limit) { return __qdf_str_nlen(str, limit); } diff --git a/qdf/libc/inc/i_qdf_str.h b/qdf/libc/inc/i_qdf_str.h index 4e8956c587..22b93c2825 100644 --- a/qdf/libc/inc/i_qdf_str.h +++ b/qdf/libc/inc/i_qdf_str.h @@ -24,8 +24,13 @@ #ifndef __I_QDF_STR_H #define __I_QDF_STR_H +#include "string.h" + #define __qdf_is_space(c) isspace(c) +#define __qdf_str_cmp(left, right) strcmp(left, right) +#define __qdf_str_lcopy(dest, src, dest_size) strlcpy(dest, src, dest_size) const char *__qdf_str_left_trim(const char *str); +#define __qdf_str_len(str) strlen(str) char *__qdf_str_trim(char *str); #define __qdf_str_nlen(str, limit) strnlen(str, limit) diff --git a/qdf/linux/src/i_qdf_mem.h b/qdf/linux/src/i_qdf_mem.h index f664e08b5a..6951d2201e 100644 --- a/qdf/linux/src/i_qdf_mem.h +++ b/qdf/linux/src/i_qdf_mem.h @@ -107,34 +107,6 @@ typedef struct __qdf_mempool_ctxt { /* typedef for dma_data_direction */ typedef enum dma_data_direction __dma_data_direction; -/** - * __qdf_str_cmp() - Compare two strings - * @str1: First string - * @str2: Second string - * - * Return: =0 equal - * >0 not equal, if str1 sorts lexicographically after str2 - * <0 not equal, if str1 sorts lexicographically before str2 - */ -static inline int32_t __qdf_str_cmp(const char *str1, const char *str2) -{ - return strcmp(str1, str2); -} - -/** - * __qdf_str_lcopy() - Copy from one string to another - * @dest: destination string - * @src: source string - * @bytes: limit of num bytes to copy - * - * @return: 0 returns the initial value of dest - */ -static inline uint32_t __qdf_str_lcopy(char *dest, const char *src, - uint32_t bytes) -{ - return strlcpy(dest, src, bytes); -} - /** * __qdf_dma_dir_to_os() - Convert DMA data direction to OS specific enum * @dir: QDF DMA data direction @@ -211,17 +183,6 @@ void __qdf_mempool_free(qdf_device_t osdev, __qdf_mempool_t pool, void *buf); #define __qdf_mempool_elem_size(_pool) ((_pool)->elem_size) #endif -/** - * __qdf_str_len() - returns the length of a string - * @str: input string - * Return: - * length of string - */ -static inline int32_t __qdf_str_len(const char *str) -{ - return strlen(str); -} - /** * __qdf_mem_cmp() - memory compare * @memory1: pointer to one location in memory to compare. diff --git a/qdf/linux/src/i_qdf_str.h b/qdf/linux/src/i_qdf_str.h index a390545a16..0f54196c36 100644 --- a/qdf/linux/src/i_qdf_str.h +++ b/qdf/linux/src/i_qdf_str.h @@ -24,11 +24,13 @@ #ifndef __I_QDF_STR_H #define __I_QDF_STR_H -#include "linux/ctype.h" #include "linux/string.h" #define __qdf_is_space(c) isspace(c) +#define __qdf_str_cmp(left, right) strcmp(left, right) +#define __qdf_str_lcopy(dest, src, dest_size) strlcpy(dest, src, dest_size) #define __qdf_str_left_trim(str) skip_spaces(str) +#define __qdf_str_len(str) strlen(str) #define __qdf_str_trim(str) strim(str) #define __qdf_str_nlen(str, limit) strnlen(str, limit)