blob: 7c38e14fc3971a42644417f9ff17b5d5cf1b5077 [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/*!
19 * @brief Internal implementation for memory copy
20 * @param[in] pvTarget the target buffer to which the data is copied into
21 * @param[in] pvSource pointer to the second memory location
22 * @param[in] u32Count the size of the data to copy
23 * @note this function should not be used directly, use WILC_memcpy instead
24 * @author syounan
25 * @date 18 Aug 2010
26 * @version 1.0
27 */
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090028void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090029
30/*!
31 * @brief Copies the contents of a memory buffer into another
32 * @param[in] pvTarget the target buffer to which the data is copied into
33 * @param[in] pvSource pointer to the second memory location
34 * @param[in] u32Count the size of the data to copy
35 * @return WILC_SUCCESS if copy is successfully handeled
36 * WILC_FAIL if copy failed
37 * @note this function repeats the functionality of standard memcpy,
38 * however memcpy is undefined if the two buffers overlap but this
39 * implementation will check for overlap and report error
40 * @author syounan
41 * @date 18 Aug 2010
42 * @version 1.0
43 */
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090044static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, u32 u32Count)
Johnny Kimc5c77ba2015-05-11 14:30:56 +090045{
46 if (
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090047 (((u8 *)pvTarget <= (u8 *)pvSource)
48 && (((u8 *)pvTarget + u32Count) > (u8 *)pvSource))
Johnny Kimc5c77ba2015-05-11 14:30:56 +090049
Greg Kroah-Hartman63d03e42015-06-02 14:16:04 +090050 || (((u8 *)pvSource <= (u8 *)pvTarget)
51 && (((u8 *)pvSource + u32Count) > (u8 *)pvTarget))
Johnny Kimc5c77ba2015-05-11 14:30:56 +090052 ) {
53 /* ovelapped memory, return Error */
54 return WILC_FAIL;
55 } else {
56 WILC_memcpy_INTERNAL(pvTarget, pvSource, u32Count);
57 return WILC_SUCCESS;
58 }
59}
60
Johnny Kimc5c77ba2015-05-11 14:30:56 +090061
62/*!
Johnny Kimc5c77ba2015-05-11 14:30:56 +090063 * @brief copies the contents of source string into the target string
64 * @param[in] pcTarget the target string buffer
65 * @param[in] pcSource the source string the will be copied
66 * @param[in] u32Count copying will proceed until a null character in pcSource
67 * is encountered or u32Count of bytes copied
68 * @return value of pcTarget
69 * @note this function repeats the functionality of standard strncpy
70 * @author syounan
71 * @date 18 Aug 2010
72 * @version 1.0
73 */
Dean Lee576917a2015-06-15 11:58:57 +090074char *WILC_strncpy(char *pcTarget, const char *pcSource,
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090075 u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090076
77/*!
Johnny Kimc5c77ba2015-05-11 14:30:56 +090078 * @brief Compares two strings up to u32Count characters
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +090079 * @details Compares 2 strings reporting which is bigger, NULL is considered
Johnny Kimc5c77ba2015-05-11 14:30:56 +090080 * the smallest string, then a zero length string then all other
81 * strings depending on thier ascii characters order with small case
82 * converted to uppder case
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +090083 * @param[in] pcStr1 the first string, NULL is valid and considered smaller
Johnny Kimc5c77ba2015-05-11 14:30:56 +090084 * than any other non-NULL string (incliding zero lenght strings)
Greg Kroah-Hartmanb1413b62015-06-02 14:11:12 +090085 * @param[in] pcStr2 the second string, NULL is valid and considered smaller
Johnny Kimc5c77ba2015-05-11 14:30:56 +090086 * than any other non-NULL string (incliding zero lenght strings)
87 * @param[in] u32Count copying will proceed until a null character in pcStr1 or
88 * pcStr2 is encountered or u32Count of bytes copied
89 * @return 0 if the 2 strings are equal, 1 if pcStr1 is bigger than pcStr2,
90 * -1 if pcStr1 smaller than pcStr2
91 * @author aabozaeid
92 * @date 7 Dec 2010
93 * @version 1.0
94 */
Dean Lee576917a2015-06-15 11:58:57 +090095s32 WILC_strncmp(const char *pcStr1, const char *pcStr2,
Chaehyun Lim4e4467f2015-06-11 14:35:55 +090096 u32 u32Count);
Johnny Kimc5c77ba2015-05-11 14:30:56 +090097
Johnny Kimc5c77ba2015-05-11 14:30:56 +090098
Johnny Kimc5c77ba2015-05-11 14:30:56 +090099#endif