diff options
Diffstat (limited to 'string')
-rw-r--r-- | string/bits/string2.h | 90 | ||||
-rw-r--r-- | string/string-inlines.c | 64 | ||||
-rw-r--r-- | string/strsep.c | 26 |
3 files changed, 67 insertions, 113 deletions
diff --git a/string/bits/string2.h b/string/bits/string2.h index e39d4f1..c136617 100644 --- a/string/bits/string2.h +++ b/string/bits/string2.h @@ -180,96 +180,6 @@ extern void *__rawmemchr (const void *__s, int __c); #endif -#if !defined _HAVE_STRING_ARCH_strsep || defined _FORCE_INLINES -# ifndef _HAVE_STRING_ARCH_strsep - -extern char *__strsep_g (char **__stringp, const char *__delim); -# define __strsep(s, reject) \ - __extension__ \ - ({ char __r0, __r1, __r2; \ - (__builtin_constant_p (reject) && __string2_1bptr_p (reject) \ - && (__r0 = ((const char *) (reject))[0], \ - ((const char *) (reject))[0] != '\0') \ - ? ((__r1 = ((const char *) (reject))[1], \ - ((const char *) (reject))[1] == '\0') \ - ? __strsep_1c (s, __r0) \ - : ((__r2 = ((const char *) (reject))[2], __r2 == '\0') \ - ? __strsep_2c (s, __r0, __r1) \ - : (((const char *) (reject))[3] == '\0' \ - ? __strsep_3c (s, __r0, __r1, __r2) \ - : __strsep_g (s, reject)))) \ - : __strsep_g (s, reject)); }) -# endif - -__STRING_INLINE char *__strsep_1c (char **__s, char __reject); -__STRING_INLINE char * -__strsep_1c (char **__s, char __reject) -{ - char *__retval = *__s; - if (__retval != NULL && (*__s = strchr (__retval, __reject)) != NULL) - *(*__s)++ = '\0'; - return __retval; -} - -__STRING_INLINE char *__strsep_2c (char **__s, char __reject1, char __reject2); -__STRING_INLINE char * -__strsep_2c (char **__s, char __reject1, char __reject2) -{ - char *__retval = *__s; - if (__retval != NULL) - { - char *__cp = __retval; - while (1) - { - if (*__cp == '\0') - { - __cp = NULL; - break; - } - if (*__cp == __reject1 || *__cp == __reject2) - { - *__cp++ = '\0'; - break; - } - ++__cp; - } - *__s = __cp; - } - return __retval; -} - -__STRING_INLINE char *__strsep_3c (char **__s, char __reject1, char __reject2, - char __reject3); -__STRING_INLINE char * -__strsep_3c (char **__s, char __reject1, char __reject2, char __reject3) -{ - char *__retval = *__s; - if (__retval != NULL) - { - char *__cp = __retval; - while (1) - { - if (*__cp == '\0') - { - __cp = NULL; - break; - } - if (*__cp == __reject1 || *__cp == __reject2 || *__cp == __reject3) - { - *__cp++ = '\0'; - break; - } - ++__cp; - } - *__s = __cp; - } - return __retval; -} -# ifdef __USE_MISC -# define strsep(s, reject) __strsep (s, reject) -# endif -#endif - /* We need the memory allocation functions for inline strdup(). Referring to stdlib.h (even minimally) is not allowed in any of the tight standards compliant modes. */ diff --git a/string/string-inlines.c b/string/string-inlines.c index d43e589..7b1de71 100644 --- a/string/string-inlines.c +++ b/string/string-inlines.c @@ -63,6 +63,70 @@ __old_strtok_r_1c (char *__s, char __sep, char **__nextp) return __result; } compat_symbol (libc, __old_strtok_r_1c, __strtok_r_1c, GLIBC_2_1_1); + +char * +__old_strsep_1c (char **__s, char __reject) +{ + char *__retval = *__s; + if (__retval != NULL && (*__s = strchr (__retval, __reject)) != NULL) + *(*__s)++ = '\0'; + return __retval; +} +compat_symbol (libc, __old_strsep_1c, __strsep_1c, GLIBC_2_1_1); + +char * +__old_strsep_2c (char **__s, char __reject1, char __reject2) +{ + char *__retval = *__s; + if (__retval != NULL) + { + char *__cp = __retval; + while (1) + { + if (*__cp == '\0') + { + __cp = NULL; + break; + } + if (*__cp == __reject1 || *__cp == __reject2) + { + *__cp++ = '\0'; + break; + } + ++__cp; + } + *__s = __cp; + } + return __retval; +} +compat_symbol (libc, __old_strsep_2c, __strsep_2c, GLIBC_2_1_1); + +char * +__old_strsep_3c (char **__s, char __reject1, char __reject2, char __reject3) +{ + char *__retval = *__s; + if (__retval != NULL) + { + char *__cp = __retval; + while (1) + { + if (*__cp == '\0') + { + __cp = NULL; + break; + } + if (*__cp == __reject1 || *__cp == __reject2 || *__cp == __reject3) + { + *__cp++ = '\0'; + break; + } + ++__cp; + } + *__s = __cp; + } + return __retval; +} +compat_symbol (libc, __old_strsep_3c, __strsep_3c, GLIBC_2_1_1); #endif #if SHLIB_COMPAT (libc, GLIBC_2_1_1, GLIBC_2_24) diff --git a/string/strsep.c b/string/strsep.c index 1054774..68581c8 100644 --- a/string/strsep.c +++ b/string/strsep.c @@ -29,30 +29,10 @@ __strsep (char **stringp, const char *delim) if (begin == NULL) return NULL; - /* A frequent case is when the delimiter string contains only one - character. Here we don't need to call the expensive `strpbrk' - function and instead work using `strchr'. */ - if (delim[0] == '\0' || delim[1] == '\0') - { - char ch = delim[0]; - - if (ch == '\0') - end = NULL; - else - { - if (*begin == ch) - end = begin; - else if (*begin == '\0') - end = NULL; - else - end = strchr (begin + 1, ch); - } - } - else - /* Find the end of the token. */ - end = strpbrk (begin, delim); + /* Find the end of the token. */ + end = begin + strcspn (begin, delim); - if (end) + if (*end) { /* Terminate the token and set *STRINGP past NUL character. */ *end++ = '\0'; |