- Timestamp:
- 09/26/08 20:42:40 (3 months ago)
- Location:
- trunk/payloads/libpayload
- Files:
-
- 2 modified
-
include/libpayload.h (modified) (2 diffs)
-
libc/string.c (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/payloads/libpayload/include/libpayload.h
r3605 r3608 111 111 112 112 /** 113 * @defgroup usb USB functions 114 * @{ 115 */ 116 int usb_initialize(void); 117 /** @} */ 118 119 /** 113 120 * @defgroup input Device functions 114 121 * @{ @} … … 316 323 char *strdup(const char *s); 317 324 char *strstr(const char *h, const char *n); 325 char *strsep(char **stringp, const char *delim); 318 326 /** @} */ 319 327 -
trunk/payloads/libpayload/libc/string.c
r3539 r3608 129 129 } 130 130 131 /** 132 * Copy a string with a maximum length. 133 * 134 * @param d The destination memory. 135 * @param s The source string. 136 * @param n Copy at most n characters as length of the string. 137 * @return A pointer to the destination memory. 138 */ 131 139 char *strncpy(char *d, const char *s, size_t n) 132 140 { … … 141 149 } 142 150 151 /** 152 * Copy a string. 153 * 154 * @param d The destination memory. 155 * @param s The source string. 156 * @return A pointer to the destination memory. 157 */ 143 158 char *strcpy(char *d, const char *s) 144 159 { … … 146 161 } 147 162 163 /** 164 * Concatenates two strings with a maximum length. 165 * 166 * @param d The destination string. 167 * @param s The source string. 168 * @param n The target string will have a length of n characters at most. 169 * @return A pointer to the destination string. 170 */ 148 171 char *strncat(char *d, const char *s, size_t n) 149 172 { … … 159 182 } 160 183 184 /** 185 * Find a character in a string. 186 * 187 * @param s The string. 188 * @param c The character. 189 * @return A pointer to the first occurence of the character in the 190 * string, or NULL if the character was not encountered within the string. 191 */ 161 192 char *strchr(const char *s, int c) 162 193 { … … 171 202 } 172 203 204 /** 205 * Duplicate a string. 206 * 207 * @param s The string to duplicate. 208 * @return A pointer to the copy of the original string. 209 */ 173 210 char *strdup(const char *s) 174 211 { … … 183 220 } 184 221 222 /** 223 * Find a substring within a string. 224 * 225 * @param h The haystack string. 226 * @param n The needle string (substring). 227 * @return A pointer to the first occurence of the substring in 228 * the string, or NULL if the substring was not encountered within the string. 229 */ 185 230 char *strstr(const char *h, const char *n) 186 231 { … … 195 240 return NULL; 196 241 } 242 243 /** 244 * Separate strings. 245 * 246 * @param stringp reference of the string to separate. 247 * @param delim string containing all delimiters. 248 * @return Token string. 249 */ 250 char *strsep(char **stringp, const char *delim) 251 { 252 char *walk, *token; 253 254 if (!stringp || !*stringp || !**stringp) 255 return NULL; 256 257 token = walk = *stringp; 258 259 /* Walk, search for delimiters */ 260 while(*walk && !strchr(delim, *walk)) 261 walk++; 262 263 if (*walk) { 264 /* NUL terminate */ 265 *walk = '\0'; 266 walk++; 267 } 268 269 *stringp = walk; 270 271 return token; 272 } 273
