blob: bb31beaf5aef1344cc7ca648b4862c078b571494 [file] [log] [blame]
Johnny Kimc5c77ba2015-05-11 14:30:56 +09001#ifndef __WILC_STRUTILS_H__
2#define __WILC_STRUTILS_H__
3
4/*!
5 * @file wilc_strutils.h
6 * @brief Basic string utilities
7 * @author syounan
8 * @sa wilc_oswrapper.h top level OS wrapper file
9 * @date 16 Aug 2010
10 * @version 1.0
11 */
12
Johnny Kimc5c77ba2015-05-11 14:30:56 +090013/*!
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
21 * @author syounan
22 * @date 18 Aug 2010
23 * @version 1.0
24 */
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +090025s32 WILC_memcmp(const void *pvArg1, const void *pvArg2, u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090026
27/*!
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
33 * @author syounan
34 * @date 18 Aug 2010
35 * @version 1.0
36 */
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090037void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090038
39/*!
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
49 * @author syounan
50 * @date 18 Aug 2010
51 * @version 1.0
52 */
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090053static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, u32 u32Count)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090054{
55 if (
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090056 (((u8 *)pvTarget <= (u8 *)pvSource)
57 && (((u8 *)pvTarget + u32Count) > (u8 *)pvSource))
Johnny Kimc5c77ba2015-05-11 14:30:56 +090058
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090059 || (((u8 *)pvSource <= (u8 *)pvTarget)
60 && (((u8 *)pvSource + u32Count) > (u8 *)pvTarget))
Johnny Kimc5c77ba2015-05-11 14:30:56 +090061 ) {
62 /* ovelapped memory, return Error */
63 return WILC_FAIL;
64 } else {
65 WILC_memcpy_INTERNAL(pvTarget, pvSource, u32Count);
66 return WILC_SUCCESS;
67 }
68}
69
70/*!
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
77 * @author syounan
78 * @date 18 Aug 2010
79 * @version 1.0
80 */
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090081void *WILC_memset(void *pvTarget, u8 u8SetValue, u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090082
83/*!
Johnny Kimc5c77ba2015-05-11 14:30:56 +090084 * @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
91 * @author syounan
92 * @date 18 Aug 2010
93 * @version 1.0
94 */
Dean Lee576917a2015-06-15 11:58:57 +090095char *WILC_strncpy(char *pcTarget, const char *pcSource,
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090096 u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090097
98/*!
Johnny Kimc5c77ba2015-05-11 14:30:56 +090099 * @brief Compares two strings up to u32Count characters
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900100 * @details Compares 2 strings reporting which is bigger, NULL is considered
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900101 * 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
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900104 * @param[in] pcStr1 the first string, NULL is valid and considered smaller
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900105 * than any other non-NULL string (incliding zero lenght strings)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900106 * @param[in] pcStr2 the second string, NULL is valid and considered smaller
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900107 * 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
112 * @author aabozaeid
113 * @date 7 Dec 2010
114 * @version 1.0
115 */
Dean Lee576917a2015-06-15 11:58:57 +0900116s32 WILC_strncmp(const char *pcStr1, const char *pcStr2,
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900117 u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900118
119/*!
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900120 * @brief gets the length of a string
121 * @param[in] pcStr the string
122 * @return the length
123 * @note this function repeats the functionality of standard strlen
124 * @author syounan
125 * @date 18 Aug 2010
126 * @version 1.0
127 */
Dean Lee576917a2015-06-15 11:58:57 +0900128u32 WILC_strlen(const char *pcStr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900129
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900130#endif