1 #ifndef __WILC_STRUTILS_H__
2 #define __WILC_STRUTILS_H__
5 * @file wilc_strutils.h
6 * @brief Basic string utilities
8 * @sa wilc_oswrapper.h top level OS wrapper file
13 #include <linux/types.h>
14 #include <linux/string.h>
15 #include "wilc_errorsupport.h"
18 * @brief Compares two memory buffers
19 * @param[in] pvArg1 pointer to the first memory location
20 * @param[in] pvArg2 pointer to the second memory location
21 * @param[in] u32Count the size of the memory buffers
22 * @return 0 if the 2 buffers are equal, 1 if pvArg1 is bigger than pvArg2,
23 * -1 if pvArg1 smaller than pvArg2
24 * @note this function repeats the functionality of standard memcmp
29 s32 WILC_memcmp(const void *pvArg1, const void *pvArg2, u32 u32Count);
32 * @brief Internal implementation for memory copy
33 * @param[in] pvTarget the target buffer to which the data is copied into
34 * @param[in] pvSource pointer to the second memory location
35 * @param[in] u32Count the size of the data to copy
36 * @note this function should not be used directly, use WILC_memcpy instead
41 void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, u32 u32Count);
44 * @brief Copies the contents of a memory buffer into another
45 * @param[in] pvTarget the target buffer to which the data is copied into
46 * @param[in] pvSource pointer to the second memory location
47 * @param[in] u32Count the size of the data to copy
48 * @return WILC_SUCCESS if copy is successfully handeled
49 * WILC_FAIL if copy failed
50 * @note this function repeats the functionality of standard memcpy,
51 * however memcpy is undefined if the two buffers overlap but this
52 * implementation will check for overlap and report error
57 static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, u32 u32Count)
60 (((u8 *)pvTarget <= (u8 *)pvSource)
61 && (((u8 *)pvTarget + u32Count) > (u8 *)pvSource))
63 || (((u8 *)pvSource <= (u8 *)pvTarget)
64 && (((u8 *)pvSource + u32Count) > (u8 *)pvTarget))
66 /* ovelapped memory, return Error */
69 WILC_memcpy_INTERNAL(pvTarget, pvSource, u32Count);
75 * @brief Sets the contents of a memory buffer with the given value
76 * @param[in] pvTarget the target buffer which contsnts will be set
77 * @param[in] u8SetValue the value to be used
78 * @param[in] u32Count the size of the memory buffer
79 * @return value of pvTarget
80 * @note this function repeats the functionality of standard memset
85 void *WILC_memset(void *pvTarget, u8 u8SetValue, u32 u32Count);
88 * @brief copies the contents of source string into the target string
89 * @param[in] pcTarget the target string buffer
90 * @param[in] pcSource the source string the will be copied
91 * @param[in] u32Count copying will proceed until a null character in pcSource
92 * is encountered or u32Count of bytes copied
93 * @return value of pcTarget
94 * @note this function repeats the functionality of standard strncpy
99 char *WILC_strncpy(char *pcTarget, const char *pcSource,
103 * @brief Compares two strings up to u32Count characters
104 * @details Compares 2 strings reporting which is bigger, NULL is considered
105 * the smallest string, then a zero length string then all other
106 * strings depending on thier ascii characters order with small case
107 * converted to uppder case
108 * @param[in] pcStr1 the first string, NULL is valid and considered smaller
109 * than any other non-NULL string (incliding zero lenght strings)
110 * @param[in] pcStr2 the second string, NULL is valid and considered smaller
111 * than any other non-NULL string (incliding zero lenght strings)
112 * @param[in] u32Count copying will proceed until a null character in pcStr1 or
113 * pcStr2 is encountered or u32Count of bytes copied
114 * @return 0 if the 2 strings are equal, 1 if pcStr1 is bigger than pcStr2,
115 * -1 if pcStr1 smaller than pcStr2
120 s32 WILC_strncmp(const char *pcStr1, const char *pcStr2,
124 * @brief gets the length of a string
125 * @param[in] pcStr the string
127 * @note this function repeats the functionality of standard strlen
132 u32 WILC_strlen(const char *pcStr);