summaryrefslogtreecommitdiff
path: root/drivers/staging/wilc1000/wilc_strutils.h
blob: 3a973a5ec61be8368cc0dbc9150b2c45ee1f364d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
#ifndef __WILC_STRUTILS_H__
#define __WILC_STRUTILS_H__

/*!
 *  @file	wilc_strutils.h
 *  @brief	Basic string utilities
 *  @author	syounan
 *  @sa		wilc_oswrapper.h top level OS wrapper file
 *  @date	16 Aug 2010
 *  @version	1.0
 */

#ifndef CONFIG_WILC_STRING_UTILS
#error the feature CONFIG_WILC_STRING_UTILS must be supported to include this file
#endif

/*!
 *  @brief	Compares two memory buffers
 *  @param[in]	pvArg1 pointer to the first memory location
 *  @param[in]	pvArg2 pointer to the second memory location
 *  @param[in]	u32Count the size of the memory buffers
 *  @return	0 if the 2 buffers are equal, 1 if pvArg1 is bigger than pvArg2,
 *              -1 if pvArg1 smaller than pvArg2
 *  @note	this function repeats the functionality of standard memcmp
 *  @author	syounan
 *  @date	18 Aug 2010
 *  @version	1.0
 */
WILC_Sint32 WILC_memcmp(const void *pvArg1, const void *pvArg2, WILC_Uint32 u32Count);

/*!
 *  @brief	Internal implementation for memory copy
 *  @param[in]	pvTarget the target buffer to which the data is copied into
 *  @param[in]	pvSource pointer to the second memory location
 *  @param[in]	u32Count the size of the data to copy
 *  @note	this function should not be used directly, use WILC_memcpy instead
 *  @author	syounan
 *  @date	18 Aug 2010
 *  @version	1.0
 */
void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, WILC_Uint32 u32Count);

/*!
 *  @brief	Copies the contents of a memory buffer into another
 *  @param[in]	pvTarget the target buffer to which the data is copied into
 *  @param[in]	pvSource pointer to the second memory location
 *  @param[in]	u32Count the size of the data to copy
 *  @return	WILC_SUCCESS if copy is successfully handeled
 *              WILC_FAIL if copy failed
 *  @note	this function repeats the functionality of standard memcpy,
 *              however memcpy is undefined if the two buffers overlap but this
 *              implementation will check for overlap and report error
 *  @author	syounan
 *  @date	18 Aug 2010
 *  @version	1.0
 */
static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, WILC_Uint32 u32Count)
{
	if (
		(((WILC_Uint8 *)pvTarget <= (WILC_Uint8 *)pvSource)
		 && (((WILC_Uint8 *)pvTarget + u32Count) > (WILC_Uint8 *)pvSource))

		|| (((WILC_Uint8 *)pvSource <= (WILC_Uint8 *)pvTarget)
		    && (((WILC_Uint8 *)pvSource + u32Count) > (WILC_Uint8 *)pvTarget))
		) {
		/* ovelapped memory, return Error */
		return WILC_FAIL;
	} else {
		WILC_memcpy_INTERNAL(pvTarget, pvSource, u32Count);
		return WILC_SUCCESS;
	}
}

/*!
 *  @brief	Sets the contents of a memory buffer with the given value
 *  @param[in]	pvTarget the target buffer which contsnts will be set
 *  @param[in]	u8SetValue the value to be used
 *  @param[in]	u32Count the size of the memory buffer
 *  @return	value of pvTarget
 *  @note	this function repeats the functionality of standard memset
 *  @author	syounan
 *  @date	18 Aug 2010
 *  @version	1.0
 */
void *WILC_memset(void *pvTarget, WILC_Uint8 u8SetValue, WILC_Uint32 u32Count);

/*!
 *  @brief	Concatenates the contents of 2 strings up to a given count
 *  @param[in]	pcTarget the target string, its null character will be overwritten
 *              and contents of pcSource will be concatentaed to it
 *  @param[in]	pcSource the source string the will be concatentaed
 *  @param[in]	u32Count copying will proceed until a null character in pcSource
 *              is encountered or u32Count of bytes copied
 *  @return	value of pcTarget
 *  @note	this function repeats the functionality of standard strncat
 *  @author	syounan
 *  @date	18 Aug 2010
 *  @version	1.0
 */
WILC_Char *WILC_strncat(WILC_Char *pcTarget, const WILC_Char *pcSource,
			WILC_Uint32 u32Count);

/*!
 *  @brief	copies the contents of source string into the target string
 *  @param[in]	pcTarget the target string buffer
 *  @param[in]	pcSource the source string the will be copied
 *  @param[in]	u32Count copying will proceed until a null character in pcSource
 *              is encountered or u32Count of bytes copied
 *  @return	value of pcTarget
 *  @note	this function repeats the functionality of standard strncpy
 *  @author	syounan
 *  @date	18 Aug 2010
 *  @version	1.0
 */
WILC_Char *WILC_strncpy(WILC_Char *pcTarget, const WILC_Char *pcSource,
			WILC_Uint32 u32Count);

/*!
 *  @brief	Compares two strings
 *  @details	Compares 2 strings reporting which is bigger, WILC_NULL is considered
 *              the smallest string, then a zero length string then all other
 *              strings depending on thier ascii characters order
 *  @param[in]	pcStr1 the first string, WILC_NULL is valid and considered smaller
 *              than any other non-NULL string (incliding zero lenght strings)
 *  @param[in]	pcStr2 the second string, WILC_NULL is valid and considered smaller
 *              than any other non-NULL string (incliding zero lenght strings)
 *  @return	0 if the 2 strings are equal, 1 if pcStr1 is bigger than pcStr2,
 *              -1 if pcStr1 smaller than pcStr2
 *  @note	this function repeats the functionality of standard strcmp
 *  @author	syounan
 *  @date	18 Aug 2010
 *  @version	1.0
 */
WILC_Sint32 WILC_strcmp(const WILC_Char *pcStr1, const WILC_Char *pcStr2);

/*!
 *  @brief	Compares two strings up to u32Count characters
 *  @details	Compares 2 strings reporting which is bigger, WILC_NULL is considered
 *              the smallest string, then a zero length string then all other
 *              strings depending on thier ascii characters order with small case
 *              converted to uppder case
 *  @param[in]	pcStr1 the first string, WILC_NULL is valid and considered smaller
 *              than any other non-NULL string (incliding zero lenght strings)
 *  @param[in]	pcStr2 the second string, WILC_NULL is valid and considered smaller
 *              than any other non-NULL string (incliding zero lenght strings)
 *  @param[in]	u32Count copying will proceed until a null character in pcStr1 or
 *              pcStr2 is encountered or u32Count of bytes copied
 *  @return	0 if the 2 strings are equal, 1 if pcStr1 is bigger than pcStr2,
 *              -1 if pcStr1 smaller than pcStr2
 *  @author	aabozaeid
 *  @date	7 Dec 2010
 *  @version	1.0
 */
WILC_Sint32 WILC_strncmp(const WILC_Char *pcStr1, const WILC_Char *pcStr2,
			 WILC_Uint32 u32Count);

/*!
 *  @brief	Compares two strings ignoring the case of its latin letters
 *  @details	Compares 2 strings reporting which is bigger, WILC_NULL is considered
 *              the smallest string, then a zero length string then all other
 *              strings depending on thier ascii characters order with small case
 *              converted to uppder case
 *  @param[in]	pcStr1 the first string, WILC_NULL is valid and considered smaller
 *              than any other non-NULL string (incliding zero lenght strings)
 *  @param[in]	pcStr2 the second string, WILC_NULL is valid and considered smaller
 *              than any other non-NULL string (incliding zero lenght strings)
 *  @return	0 if the 2 strings are equal, 1 if pcStr1 is bigger than pcStr2,
 *              -1 if pcStr1 smaller than pcStr2
 *  @author	syounan
 *  @date	1 Nov 2010
 *  @version	2.0
 */
WILC_Sint32 WILC_strcmp_IgnoreCase(const WILC_Char *pcStr1, const WILC_Char *pcStr2);

/*!
 *  @brief	Compares two strings ignoring the case of its latin letters up to
 *		u32Count characters
 *  @details	Compares 2 strings reporting which is bigger, WILC_NULL is considered
 *              the smallest string, then a zero length string then all other
 *              strings depending on thier ascii characters order with small case
 *              converted to uppder case
 *  @param[in]	pcStr1 the first string, WILC_NULL is valid and considered smaller
 *              than any other non-NULL string (incliding zero lenght strings)
 *  @param[in]	pcStr2 the second string, WILC_NULL is valid and considered smaller
 *              than any other non-NULL string (incliding zero lenght strings)
 *  @param[in]	u32Count copying will proceed until a null character in pcStr1 or
 *              pcStr2 is encountered or u32Count of bytes copied
 *  @return	0 if the 2 strings are equal, 1 if pcStr1 is bigger than pcStr2,
 *              -1 if pcStr1 smaller than pcStr2
 *  @author	aabozaeid
 *  @date	7 Dec 2010
 *  @version	1.0
 */
WILC_Sint32 WILC_strncmp_IgnoreCase(const WILC_Char *pcStr1, const WILC_Char *pcStr2,
				    WILC_Uint32 u32Count);

/*!
 *  @brief	gets the length of a string
 *  @param[in]	pcStr the string
 *  @return	the length
 *  @note	this function repeats the functionality of standard strlen
 *  @author	syounan
 *  @date	18 Aug 2010
 *  @version	1.0
 */
WILC_Uint32 WILC_strlen(const WILC_Char *pcStr);

/*!
 *  @brief	convert string to integer
 *  @param[in]	pcStr the string
 *  @return	the value of string
 *  @note	this function repeats the functionality of the libc atoi
 *  @author	bfahmy
 *  @date	28 Aug 2010
 *  @version	1.0
 */
WILC_Sint32 WILC_strtoint(const WILC_Char *pcStr);

/*!
 *  @brief	print a formatted string into a buffer
 *  @param[in]	pcTarget the buffer where the resulting string is written
 *  @param[in]	u32Size size of the output beffer including the \0 terminating
 *              character
 *  @param[in]	pcFormat format of the string
 *  @return	number of character written or would have been written if the
 *              string were not truncated
 *  @note	this function repeats the functionality of standard snprintf
 *  @author	syounan
 *  @date	1 Nov 2010
 *  @version	2.0
 */
WILC_Sint32 WILC_snprintf(WILC_Char *pcTarget, WILC_Uint32 u32Size,
			  const WILC_Char *pcFormat, ...);


#ifdef CONFIG_WILC_EXTENDED_STRING_OPERATIONS


/**
 *  @brief
 *  @details    Searches for the first occurrence of the character c in the first n bytes
 *                              of the string pointed to by the argument str.
 *                              Returns a pointer pointing to the first matching character,
 *                              or null if no match was found.
 *  @param[in]
 *  @return
 *  @note
 *  @author		remil
 *  @date		3 Nov 2010
 *  @version		1.0
 */
WILC_Char *WILC_memchr(const void *str, WILC_Char c, WILC_Sint32 n);

/**
 *  @brief
 *  @details    Searches for the first occurrence of the character c (an unsigned char)
 *                              in the string pointed to by the argument str.
 *                              The terminating null character is considered to be part of the string.
 *                              Returns a pointer pointing to the first matching character,
 *                              or null if no match was found.
 *  @param[in]
 *  @return
 *  @note
 *  @author		remil
 *  @date		3 Nov 2010
 *  @version		1.0
 */
WILC_Char *WILC_strchr(const WILC_Char *str, WILC_Char c);

/**
 *  @brief
 *  @details    Appends the string pointed to by str2 to the end of the string pointed to by str1.
 *                              The terminating null character of str1 is overwritten.
 *                              Copying stops once the terminating null character of str2 is copied. If overlapping occurs, the result is undefined.
 *                              The argument str1 is returned.
 *  @param[in]  WILC_Char* str1,
 *  @param[in]  WILC_Char* str2,
 *  @return             WILC_Char*
 *  @note
 *  @author		remil
 *  @date		3 Nov 2010
 *  @version		1.0
 */
WILC_Char *WILC_strcat(WILC_Char *str1, const WILC_Char *str2);


/**
 *  @brief
 *  @details    Copy pcSource to pcTarget
 *  @param[in]  WILC_Char* pcTarget
 *  @param[in]  const WILC_Char* pcSource
 *  @return             WILC_Char*
 *  @note
 *  @author		remil
 *  @date		3 Nov 2010
 *  @version		1.0
 */
WILC_Char *WILC_strcpy(WILC_Char *pcTarget, const WILC_Char *pcSource);



/**
 *  @brief
 *  @details    Finds the first sequence of characters in the string str1 that
 *                              does not contain any character specified in str2.
 *                              Returns the length of this first sequence of characters found that
 *                              do not match with str2.
 *  @param[in]  const WILC_Char *str1
 *  @param[in]  const WILC_Char *str2
 *  @return             WILC_Uint32
 *  @note
 *  @author		remil
 *  @date		3 Nov 2010
 *  @version		1.0
 */
WILC_Uint32 WILC_strcspn(const WILC_Char *str1, const WILC_Char *str2);


/**
 *  @brief
 *  @details    Searches an internal array for the error number errnum and returns a pointer
 *                              to an error message string.
 *                              Returns a pointer to an error message string.
 *  @param[in]  WILC_Sint32 errnum
 *  @return             WILC_Char*
 *  @note
 *  @author		remil
 *  @date		3 Nov 2010
 *  @version		1.0
 */
WILC_Char *WILC_strerror(WILC_Sint32 errnum);

/**
 *  @brief
 *  @details    Finds the first occurrence of the entire string str2
 *                              (not including the terminating null character) which appears in the string str1.
 *                              Returns a pointer to the first occurrence of str2 in str1.
 *                              If no match was found, then a null pointer is returned.
 *                              If str2 points to a string of zero length, then the argument str1 is returned.
 *  @param[in]  const WILC_Char *str1
 *  @param[in]  const WILC_Char *str2
 *  @return             WILC_Char*
 *  @note
 *  @author		remil
 *  @date		3 Nov 2010
 *  @version		1.0
 */
WILC_Char *WILC_strstr(const WILC_Char *str1, const WILC_Char *str2);

/**
 *  @brief
 *  @details    Searches for the first occurrence of the character c (an unsigned char)
 *                              in the string pointed to by the argument str.
 *                              The terminating null character is considered to be part of the string.
 *                              Returns a pointer pointing to the first matching character,
 *                              or null if no match was found.
 *  @param[in]
 *  @return
 *  @note
 *  @author		remil
 *  @date		3 Nov 2010
 *  @version		1.0
 */
WILC_Char *WILC_strchr(const WILC_Char *str, WILC_Char c);


/**
 *  @brief
 *  @details    Parses the C string str interpreting its content as a floating point
 *                              number and returns its value as a double.
 *                              If endptr is not a null pointer, the function also sets the value pointed
 *                              by endptr to point to the first character after the number.
 *  @param[in]  const WILC_Char* str
 *  @param[in]  WILC_Char** endptr
 *  @return             WILC_Double
 *  @note
 *  @author		remil
 *  @date		11 Nov 2010
 *  @version		1.0
 */
WILC_Double WILC_StringToDouble(const WILC_Char *str,
				WILC_Char **endptr);


/**
 *  @brief              Parses the C string str interpreting its content as an unsigned integral
 *                              number of the specified base, which is returned as an unsigned long int value.
 *  @details    The function first discards as many whitespace characters as necessary
 *                              until the first non-whitespace character is found.
 *                              Then, starting from this character, takes as many characters as possible
 *                              that are valid following a syntax that depends on the base parameter,
 *                              and interprets them as a numerical value.
 *                              Finally, a pointer to the first character following the integer
 *                              representation in str is stored in the object pointed by endptr.
 *  @param[in]  const WILC_Char *str
 *  @param[in]	WILC_Char **endptr
 *  @param[in]	WILC_Sint32 base
 *  @return             WILC_Uint32
 *  @note
 *  @author		remil
 *  @date		11 Nov 2010
 *  @version		1.0
 */
WILC_Uint32 WILC_StringToUint32(const WILC_Char *str,
				WILC_Char **endptr,
				WILC_Sint32 base);



#endif

#endif