Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Chaehyun Lim | fb4ec9c | 2015-06-11 14:35:59 +0900 | [diff] [blame] | 25 | s32 WILC_memcmp(const void *pvArg1, const void *pvArg2, u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 37 | void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 53 | static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, u32 u32Count) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 54 | { |
| 55 | if ( |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 56 | (((u8 *)pvTarget <= (u8 *)pvSource) |
| 57 | && (((u8 *)pvTarget + u32Count) > (u8 *)pvSource)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 58 | |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 59 | || (((u8 *)pvSource <= (u8 *)pvTarget) |
| 60 | && (((u8 *)pvSource + u32Count) > (u8 *)pvTarget)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 81 | void *WILC_memset(void *pvTarget, u8 u8SetValue, u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 82 | |
| 83 | /*! |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Dean Lee | 576917a | 2015-06-15 11:58:57 +0900 | [diff] [blame^] | 95 | char *WILC_strncpy(char *pcTarget, const char *pcSource, |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 96 | u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 97 | |
| 98 | /*! |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 99 | * @brief Compares two strings up to u32Count characters |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 100 | * @details Compares 2 strings reporting which is bigger, NULL is considered |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 104 | * @param[in] pcStr1 the first string, NULL is valid and considered smaller |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 105 | * than any other non-NULL string (incliding zero lenght strings) |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 106 | * @param[in] pcStr2 the second string, NULL is valid and considered smaller |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Dean Lee | 576917a | 2015-06-15 11:58:57 +0900 | [diff] [blame^] | 116 | s32 WILC_strncmp(const char *pcStr1, const char *pcStr2, |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 117 | u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 118 | |
| 119 | /*! |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Dean Lee | 576917a | 2015-06-15 11:58:57 +0900 | [diff] [blame^] | 128 | u32 WILC_strlen(const char *pcStr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 129 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 130 | #endif |