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 | /*! |
| 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 Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 28 | void WILC_memcpy_INTERNAL(void *pvTarget, const void *pvSource, u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 29 | |
| 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 Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 44 | static WILC_ErrNo WILC_memcpy(void *pvTarget, const void *pvSource, u32 u32Count) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 45 | { |
| 46 | if ( |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 47 | (((u8 *)pvTarget <= (u8 *)pvSource) |
| 48 | && (((u8 *)pvTarget + u32Count) > (u8 *)pvSource)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 49 | |
Greg Kroah-Hartman | 63d03e4 | 2015-06-02 14:16:04 +0900 | [diff] [blame] | 50 | || (((u8 *)pvSource <= (u8 *)pvTarget) |
| 51 | && (((u8 *)pvSource + u32Count) > (u8 *)pvTarget)) |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 52 | ) { |
| 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 Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 61 | |
| 62 | /*! |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 63 | * @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 Lee | 576917a | 2015-06-15 11:58:57 +0900 | [diff] [blame] | 74 | char *WILC_strncpy(char *pcTarget, const char *pcSource, |
Chaehyun Lim | 4e4467f | 2015-06-11 14:35:55 +0900 | [diff] [blame] | 75 | u32 u32Count); |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 76 | |
| 77 | /*! |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 78 | * @brief Compares two strings up to u32Count characters |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 79 | * @details Compares 2 strings reporting which is bigger, NULL is considered |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 80 | * 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-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 83 | * @param[in] pcStr1 the first string, NULL is valid and considered smaller |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 84 | * than any other non-NULL string (incliding zero lenght strings) |
Greg Kroah-Hartman | b1413b6 | 2015-06-02 14:11:12 +0900 | [diff] [blame] | 85 | * @param[in] pcStr2 the second string, NULL is valid and considered smaller |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 86 | * 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 Lee | 576917a | 2015-06-15 11:58:57 +0900 | [diff] [blame] | 95 | s32 WILC_strncmp(const char *pcStr1, const char *pcStr2, |
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 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 98 | |
Johnny Kim | c5c77ba | 2015-05-11 14:30:56 +0900 | [diff] [blame] | 99 | #endif |