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
14 * @brief Compares two memory buffers
15 * @param[in] pvArg1 pointer to the first memory location
16 * @param[in] pvArg2 pointer to the second memory location
17 * @param[in] u32Count the size of the memory buffers
18 * @return 0 if the 2 buffers are equal, 1 if pvArg1 is bigger than pvArg2,
19 * -1 if pvArg1 smaller than pvArg2
20 * @note this function repeats the functionality of standard memcmp
25 WILC_Sint32 WILC_memcmp(const void *pvArg1, const void *pvArg2, WILC_Uint32 u32Count);
28 * @brief Internal implementation for memory copy
29 * @param[in] pvTarget the target buffer to which the data is copied into
30 * @param[in] pvSource pointer to the second memory location
31 * @param[in] u32Count the size of the data to copy
32 * @note this function should not be used directly, use WILC_memcpy instead
37 void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, WILC_Uint32 u32Count);
40 * @brief Copies the contents of a memory buffer into another
41 * @param[in] pvTarget the target buffer to which the data is copied into
42 * @param[in] pvSource pointer to the second memory location
43 * @param[in] u32Count the size of the data to copy
44 * @return WILC_SUCCESS if copy is successfully handeled
45 * WILC_FAIL if copy failed
46 * @note this function repeats the functionality of standard memcpy,
47 * however memcpy is undefined if the two buffers overlap but this
48 * implementation will check for overlap and report error
53 static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, WILC_Uint32 u32Count)
56 (((u8 *)pvTarget <= (u8 *)pvSource)
57 && (((u8 *)pvTarget + u32Count) > (u8 *)pvSource))
59 || (((u8 *)pvSource <= (u8 *)pvTarget)
60 && (((u8 *)pvSource + u32Count) > (u8 *)pvTarget))
62 /* ovelapped memory, return Error */
65 WILC_memcpy_INTERNAL(pvTarget, pvSource, u32Count);
71 * @brief Sets the contents of a memory buffer with the given value
72 * @param[in] pvTarget the target buffer which contsnts will be set
73 * @param[in] u8SetValue the value to be used
74 * @param[in] u32Count the size of the memory buffer
75 * @return value of pvTarget
76 * @note this function repeats the functionality of standard memset
81 void *WILC_memset(void *pvTarget, u8 u8SetValue, WILC_Uint32 u32Count);
84 * @brief copies the contents of source string into the target string
85 * @param[in] pcTarget the target string buffer
86 * @param[in] pcSource the source string the will be copied
87 * @param[in] u32Count copying will proceed until a null character in pcSource
88 * is encountered or u32Count of bytes copied
89 * @return value of pcTarget
90 * @note this function repeats the functionality of standard strncpy
95 WILC_Char *WILC_strncpy(WILC_Char *pcTarget, const WILC_Char *pcSource,
96 WILC_Uint32 u32Count);
99 * @brief Compares two strings up to u32Count characters
100 * @details Compares 2 strings reporting which is bigger, NULL is considered
101 * the smallest string, then a zero length string then all other
102 * strings depending on thier ascii characters order with small case
103 * converted to uppder case
104 * @param[in] pcStr1 the first string, NULL is valid and considered smaller
105 * than any other non-NULL string (incliding zero lenght strings)
106 * @param[in] pcStr2 the second string, NULL is valid and considered smaller
107 * than any other non-NULL string (incliding zero lenght strings)
108 * @param[in] u32Count copying will proceed until a null character in pcStr1 or
109 * pcStr2 is encountered or u32Count of bytes copied
110 * @return 0 if the 2 strings are equal, 1 if pcStr1 is bigger than pcStr2,
111 * -1 if pcStr1 smaller than pcStr2
116 WILC_Sint32 WILC_strncmp(const WILC_Char *pcStr1, const WILC_Char *pcStr2,
117 WILC_Uint32 u32Count);
120 * @brief gets the length of a string
121 * @param[in] pcStr the string
123 * @note this function repeats the functionality of standard strlen
128 WILC_Uint32 WILC_strlen(const WILC_Char *pcStr);