blob: d1445575a25e1008d0f378d4899eafa49a1e5e00 [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
Dean Leec3ea8a72015-06-16 15:28:21 +090013#include <linux/types.h>
14#include <linux/string.h>
15#include "wilc_errorsupport.h"
16
Johnny Kimc5c77ba2015-05-11 14:30:56 +090017/*!
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
25 * @author syounan
26 * @date 18 Aug 2010
27 * @version 1.0
28 */
Chaehyun Limfb4ec9c2015-06-11 14:35:59 +090029s32 WILC_memcmp(const void *pvArg1, const void *pvArg2, u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090030
31/*!
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
37 * @author syounan
38 * @date 18 Aug 2010
39 * @version 1.0
40 */
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090041void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090042
43/*!
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
53 * @author syounan
54 * @date 18 Aug 2010
55 * @version 1.0
56 */
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090057static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, u32 u32Count)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090058{
59 if (
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090060 (((u8 *)pvTarget <= (u8 *)pvSource)
61 && (((u8 *)pvTarget + u32Count) > (u8 *)pvSource))
Johnny Kimc5c77ba2015-05-11 14:30:56 +090062
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090063 || (((u8 *)pvSource <= (u8 *)pvTarget)
64 && (((u8 *)pvSource + u32Count) > (u8 *)pvTarget))
Johnny Kimc5c77ba2015-05-11 14:30:56 +090065 ) {
66 /* ovelapped memory, return Error */
67 return WILC_FAIL;
68 } else {
69 WILC_memcpy_INTERNAL(pvTarget, pvSource, u32Count);
70 return WILC_SUCCESS;
71 }
72}
73
74/*!
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
81 * @author syounan
82 * @date 18 Aug 2010
83 * @version 1.0
84 */
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090085void *WILC_memset(void *pvTarget, u8 u8SetValue, u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090086
87/*!
Johnny Kimc5c77ba2015-05-11 14:30:56 +090088 * @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
95 * @author syounan
96 * @date 18 Aug 2010
97 * @version 1.0
98 */
Dean Lee576917a2015-06-15 11:58:57 +090099char *WILC_strncpy(char *pcTarget, const char *pcSource,
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900100 u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900101
102/*!
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900103 * @brief Compares two strings up to u32Count characters
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900104 * @details Compares 2 strings reporting which is bigger, NULL is considered
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900105 * 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
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900108 * @param[in] pcStr1 the first string, NULL is valid and considered smaller
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900109 * than any other non-NULL string (incliding zero lenght strings)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +0900110 * @param[in] pcStr2 the second string, NULL is valid and considered smaller
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900111 * 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
116 * @author aabozaeid
117 * @date 7 Dec 2010
118 * @version 1.0
119 */
Dean Lee576917a2015-06-15 11:58:57 +0900120s32 WILC_strncmp(const char *pcStr1, const char *pcStr2,
Chaehyun Lim4e4467f2015-06-11 14:35:55 +0900121 u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900122
123/*!
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900124 * @brief gets the length of a string
125 * @param[in] pcStr the string
126 * @return the length
127 * @note this function repeats the functionality of standard strlen
128 * @author syounan
129 * @date 18 Aug 2010
130 * @version 1.0
131 */
Dean Lee576917a2015-06-15 11:58:57 +0900132u32 WILC_strlen(const char *pcStr);
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900133
Johnny Kimc5c77ba2015-05-11 14:30:56 +0900134#endif