diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-05-10 04:23:19 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-05-10 04:23:19 +0000 |
commit | 8d9ef2675702a7c9c28008b0bff356bcc2783ac4 (patch) | |
tree | 035892720d4d965f5779a9cc40cac9e97eb21136 | |
parent | 1077fa4d772832f77a677ce7fb7c2d513b959e3f (diff) |
Add in _dl_strrchr
-rw-r--r-- | ldso/ldso/ld_string.h | 26 | ||||
-rw-r--r-- | ldso/ldso/string.h | 26 |
2 files changed, 42 insertions, 10 deletions
diff --git a/ldso/ldso/ld_string.h b/ldso/ldso/ld_string.h index 5d18bb788..5e912ea9d 100644 --- a/ldso/ldso/ld_string.h +++ b/ldso/ldso/ld_string.h @@ -7,6 +7,15 @@ #define NULL ((void *) 0) #endif +extern inline size_t _dl_strlen(const char * str) +{ + register char *ptr = (char *) str; + + while (*ptr) + ptr++; + return (ptr - str); +} + extern inline char * _dl_strcpy(char * dst,const char *src) { register char *ptr = dst; @@ -63,14 +72,22 @@ extern inline char * _dl_strchr(const char * str,int c) return 0; } - -extern inline size_t _dl_strlen(const char * str) +static inline char *_dl_strrchr(const char *str, int c) { + register char *prev = 0; register char *ptr = (char *) str; - while (*ptr) + /* For null it's just like strlen */ + if (c == '\0') { + return ptr + _dl_strlen(ptr); + } + + /* everything else just step along the string. */ + while ((ptr = _dl_strchr(ptr, c)) != 0) { + prev = ptr; ptr++; - return (ptr - str); + } + return prev; } extern inline void * _dl_memcpy(void * dst, const void * src, size_t len) @@ -143,5 +160,4 @@ static inline char *_dl_simple_ltoahex(unsigned long i) return p + 1; } - #endif diff --git a/ldso/ldso/string.h b/ldso/ldso/string.h index 5d18bb788..5e912ea9d 100644 --- a/ldso/ldso/string.h +++ b/ldso/ldso/string.h @@ -7,6 +7,15 @@ #define NULL ((void *) 0) #endif +extern inline size_t _dl_strlen(const char * str) +{ + register char *ptr = (char *) str; + + while (*ptr) + ptr++; + return (ptr - str); +} + extern inline char * _dl_strcpy(char * dst,const char *src) { register char *ptr = dst; @@ -63,14 +72,22 @@ extern inline char * _dl_strchr(const char * str,int c) return 0; } - -extern inline size_t _dl_strlen(const char * str) +static inline char *_dl_strrchr(const char *str, int c) { + register char *prev = 0; register char *ptr = (char *) str; - while (*ptr) + /* For null it's just like strlen */ + if (c == '\0') { + return ptr + _dl_strlen(ptr); + } + + /* everything else just step along the string. */ + while ((ptr = _dl_strchr(ptr, c)) != 0) { + prev = ptr; ptr++; - return (ptr - str); + } + return prev; } extern inline void * _dl_memcpy(void * dst, const void * src, size_t len) @@ -143,5 +160,4 @@ static inline char *_dl_simple_ltoahex(unsigned long i) return p + 1; } - #endif |