ddc54ab21f67bd510d84ad13602eade6039c1908
[platform/kernel/linux-starfive.git] / drivers / staging / wilc1000 / wilc_strutils.h
1 #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
13 /*!
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  */
25 WILC_Sint32 WILC_memcmp(const void *pvArg1, const void *pvArg2, WILC_Uint32 u32Count);
26
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  */
37 void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, WILC_Uint32 u32Count);
38
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  */
53 static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, WILC_Uint32 u32Count)
54 {
55         if (
56                 (((u8 *)pvTarget <= (u8 *)pvSource)
57                  && (((u8 *)pvTarget + u32Count) > (u8 *)pvSource))
58
59                 || (((u8 *)pvSource <= (u8 *)pvTarget)
60                     && (((u8 *)pvSource + u32Count) > (u8 *)pvTarget))
61                 ) {
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  */
81 void *WILC_memset(void *pvTarget, u8 u8SetValue, WILC_Uint32 u32Count);
82
83 /*!
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
91  *  @author     syounan
92  *  @date       18 Aug 2010
93  *  @version    1.0
94  */
95 WILC_Char *WILC_strncpy(WILC_Char *pcTarget, const WILC_Char *pcSource,
96                         WILC_Uint32 u32Count);
97
98 /*!
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
112  *  @author     aabozaeid
113  *  @date       7 Dec 2010
114  *  @version    1.0
115  */
116 WILC_Sint32 WILC_strncmp(const WILC_Char *pcStr1, const WILC_Char *pcStr2,
117                          WILC_Uint32 u32Count);
118
119 /*!
120  *  @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  */
128 WILC_Uint32 WILC_strlen(const WILC_Char *pcStr);
129
130 #endif