Changeset 2f57690 in mainline for kernel/generic/src/lib/string.c
- Timestamp:
- 2009-03-03T12:41:39Z (16 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- deca67b
- Parents:
- 561db3f
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/lib/string.c
r561db3f r2f57690 27 27 */ 28 28 29 /** @addtogroup generic 29 /** @addtogroup generic 30 30 * @{ 31 31 */ … … 33 33 /** 34 34 * @file 35 * @brief 35 * @brief Miscellaneous functions. 36 36 */ 37 37 … … 48 48 * 49 49 * @return Number of characters in str. 50 * 50 51 */ 51 52 size_t strlen(const char *str) … … 53 54 int i; 54 55 55 for (i = 0; str[i]; i++) 56 ; 56 for (i = 0; str[i]; i++); 57 57 58 58 return i; … … 81 81 if (*src == *dst) 82 82 return 0; 83 83 84 if (!*src) 84 85 return -1; 86 85 87 return 1; 86 88 } … … 108 110 if (*src < *dst) 109 111 return -1; 112 110 113 if (*src > *dst) 111 114 return 1; 112 115 } 116 113 117 if (i == len || *src == *dst) 114 118 return 0; 119 115 120 if (!*src) 116 121 return -1; 122 117 123 return 1; 118 124 } … … 126 132 * last copied character. 127 133 * 128 * @param src Source string.134 * @param src Source string. 129 135 * @param dest Destination buffer. 130 * @param len Size of destination buffer. 136 * @param len Size of destination buffer. 137 * 131 138 */ 132 139 void strncpy(char *dest, const char *src, size_t len) 133 140 { 134 141 unsigned int i; 135 142 136 143 for (i = 0; i < len; i++) { 137 144 if (!(dest[i] = src[i])) 138 145 return; 139 146 } 140 147 141 148 dest[i - 1] = '\0'; 142 149 } … … 144 151 /** Find first occurence of character in string. 145 152 * 146 * @param s 147 * @param i 153 * @param s String to search. 154 * @param i Character to look for. 148 155 * 149 * @return 156 * @return Pointer to character in @a s or NULL if not found. 150 157 */ 151 158 extern char *strchr(const char *s, int i) 152 159 { 153 160 while (*s != '\0') { 154 if (*s == i) return (char *) s; 161 if (*s == i) 162 return (char *) s; 155 163 ++s; 156 164 } 157 165 158 166 return NULL; 159 167 }
Note:
See TracChangeset
for help on using the changeset viewer.