Merge tag 'efi-urgent' of git://git.kernel.org/pub/scm/linux/kernel/git/mfleming...
[linux-2.6-block.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 #include <linux/types.h>
14 #include <linux/string.h>
15 #include "wilc_errorsupport.h"
16
17 /*!
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  */
29 s32 WILC_memcmp(const void *pvArg1, const void *pvArg2, u32 u32Count);
30
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  */
41 void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, u32 u32Count);
42
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  */
57 static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, u32 u32Count)
58 {
59         if (
60                 (((u8 *)pvTarget <= (u8 *)pvSource)
61                  && (((u8 *)pvTarget + u32Count) > (u8 *)pvSource))
62
63                 || (((u8 *)pvSource <= (u8 *)pvTarget)
64                     && (((u8 *)pvSource + u32Count) > (u8 *)pvTarget))
65                 ) {
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  */
85 void *WILC_memset(void *pvTarget, u8 u8SetValue, u32 u32Count);
86
87 /*!
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
95  *  @author     syounan
96  *  @date       18 Aug 2010
97  *  @version    1.0
98  */
99 char *WILC_strncpy(char *pcTarget, const char *pcSource,
100                         u32 u32Count);
101
102 /*!
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
116  *  @author     aabozaeid
117  *  @date       7 Dec 2010
118  *  @version    1.0
119  */
120 s32 WILC_strncmp(const char *pcStr1, const char *pcStr2,
121                          u32 u32Count);
122
123 /*!
124  *  @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  */
132 u32 WILC_strlen(const char *pcStr);
133
134 #endif