Changeset 517cedc0 in mainline
- Timestamp:
- 2011-07-01T19:30:59Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- b52ef5a
- Parents:
- 65ed8f4
- Location:
- uspace/lib/posix
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/lib/posix/string.c
r65ed8f4 r517cedc0 44 44 45 45 /** 46 * Defined for convenience. Returns pointer to the terminating nul character.47 *48 * @param s49 * @return50 */51 static char *strzero(const char *s)52 {53 while (*s != '\0') {54 s++;55 }56 57 return (char *) s;58 }59 60 /**61 46 * Returns true if s2 is a prefix of s1. 62 47 * … … 183 168 assert(src != NULL); 184 169 185 posix_strcpy( strzero(dest), src);170 posix_strcpy(posix_strchr(dest, '\0'), src); 186 171 return dest; 187 172 } … … 199 184 assert(src != NULL); 200 185 201 char *zeroptr = posix_strncpy( strzero(dest), src, n);186 char *zeroptr = posix_strncpy(posix_strchr(dest, '\0'), src, n); 202 187 /* strncpy doesn't append the nul terminator, so we do it here */ 203 188 zeroptr[n] = '\0'; … … 360 345 assert(s != NULL); 361 346 362 /* special handling for the case that zero is searched for */ 363 if (c == '\0') { 364 return strzero(s); 365 } 366 367 /* otherwise just loop through the string until found */ 368 while (*s != (char) c) { 369 if (*s == '\0') { 370 return NULL; 371 } 372 373 s++; 374 } 375 376 return (char *) s; 347 char *res = gnu_strchrnul(s, c); 348 return (*res == c) ? res : NULL; 377 349 } 378 350 … … 387 359 assert(s != NULL); 388 360 389 const char *ptr = strzero(s);361 const char *ptr = posix_strchr(s, '\0'); 390 362 391 363 /* the same as in strchr, except it loops in reverse direction */ … … 399 371 400 372 return (char *) ptr; 373 } 374 375 char *gnu_strchrnul(const char *s, int c) 376 { 377 assert(s != NULL); 378 379 while (*s != c && *s != '\0') { 380 s++; 381 } 382 383 return (char *) s; 401 384 } 402 385 … … 562 545 assert(s != NULL); 563 546 564 return (size_t) ( strzero(s) - s);547 return (size_t) (posix_strchr(s, '\0') - s); 565 548 } 566 549 -
uspace/lib/posix/string.h
r65ed8f4 r517cedc0 85 85 extern char *posix_strchr(const char *s, int c); 86 86 extern char *posix_strrchr(const char *s, int c); 87 extern char *gnu_strchrnul(const char *s, int c); 87 88 extern char *posix_strpbrk(const char *s1, const char *s2); 88 89 extern size_t posix_strcspn(const char *s1, const char *s2); … … 127 128 #define strchr posix_strchr 128 129 #define strrchr posix_strrchr 130 #define strchrnul gnu_strchrnul 129 131 #define strpbrk posix_strpbrk 130 132 #define strcspn posix_strcspn
Note:
See TracChangeset
for help on using the changeset viewer.