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 | |
Dean Lee | c3ea8a7 | 2015-06-16 15:28:21 +0900 | [diff] [blame^] | 13 | #include <linux/types.h> |
| 14 | #include <linux/string.h> |
| 15 | #include "wilc_errorsupport.h" |
| 16 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Chaehyun Lim | fb4ec9c | 2015-06-11 14:35:59 +0900 | [diff] [blame] | 29 | s32 WILC_memcmp(const void *pvArg1, const void *pvArg2, u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 41 | void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 57 | static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, u32 u32Count) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 58 | { |
| 59 | if ( |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 60 | (((u8 *)pvTarget <= (u8 *)pvSource) |
| 61 | && (((u8 *)pvTarget + u32Count) > (u8 *)pvSource)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 62 | |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 63 | || (((u8 *)pvSource <= (u8 *)pvTarget) |
| 64 | && (((u8 *)pvSource + u32Count) > (u8 *)pvTarget)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 85 | void *WILC_memset(void *pvTarget, u8 u8SetValue, u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 86 | |
| 87 | /*! |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Dean Lee | 576917a | 2015-06-15 11:58:57 +0900 | [diff] [blame] | 99 | char *WILC_strncpy(char *pcTarget, const char *pcSource, |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 100 | u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 101 | |
| 102 | /*! |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 103 | * @brief Compares two strings up to u32Count characters |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 104 | * @details Compares 2 strings reporting which is bigger, NULL is considered |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 108 | * @param[in] pcStr1 the first string, NULL is valid and considered smaller |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 109 | * than any other non-NULL string (incliding zero lenght strings) |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 110 | * @param[in] pcStr2 the second string, NULL is valid and considered smaller |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Dean Lee | 576917a | 2015-06-15 11:58:57 +0900 | [diff] [blame] | 120 | s32 WILC_strncmp(const char *pcStr1, const char *pcStr2, |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 121 | u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 122 | |
| 123 | /*! |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 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 | */ |
Dean Lee | 576917a | 2015-06-15 11:58:57 +0900 | [diff] [blame] | 132 | u32 WILC_strlen(const char *pcStr); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 133 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 134 | #endif |