#ifndef _PPC_STRING_H_
|
#ifndef _PPC_STRING_H_
|
#define _PPC_STRING_H_
|
#define _PPC_STRING_H_
|
|
|
|
|
|
|
/*
|
/*
|
* keep things happy, the compile became unhappy since memset is
|
* keep things happy, the compile became unhappy since memset is
|
* in include/string.h and lib/string.c with different args
|
* in include/string.h and lib/string.c with different args
|
* -- Cort
|
* -- Cort
|
*/
|
*/
|
|
|
#define __HAVE_ARCH_MEMSET
|
#define __HAVE_ARCH_MEMSET
|
extern inline void * memset(void * s,int c,size_t count)
|
extern inline void * memset(void * s,int c,size_t count)
|
{
|
{
|
char *xs = (char *) s;
|
char *xs = (char *) s;
|
|
|
while (count--)
|
while (count--)
|
*xs++ = c;
|
*xs++ = c;
|
|
|
return s;
|
return s;
|
}
|
}
|
#define __HAVE_ARCH_STRSTR
|
#define __HAVE_ARCH_STRSTR
|
/* Return the first occurrence of NEEDLE in HAYSTACK. */
|
/* Return the first occurrence of NEEDLE in HAYSTACK. */
|
extern inline char *
|
extern inline char *
|
strstr(const char *haystack, const char *needle)
|
strstr(const char *haystack, const char *needle)
|
{
|
{
|
const char *const needle_end = strchr(needle, '\0');
|
const char *const needle_end = strchr(needle, '\0');
|
const char *const haystack_end = strchr(haystack, '\0');
|
const char *const haystack_end = strchr(haystack, '\0');
|
const size_t needle_len = needle_end - needle;
|
const size_t needle_len = needle_end - needle;
|
const size_t needle_last = needle_len - 1;
|
const size_t needle_last = needle_len - 1;
|
const char *begin;
|
const char *begin;
|
|
|
if (needle_len == 0)
|
if (needle_len == 0)
|
#ifdef __linux__
|
#ifdef __linux__
|
return (char *) haystack;
|
return (char *) haystack;
|
#else
|
#else
|
return (char *) haystack_end;
|
return (char *) haystack_end;
|
#endif
|
#endif
|
if ((size_t) (haystack_end - haystack) < needle_len)
|
if ((size_t) (haystack_end - haystack) < needle_len)
|
return NULL;
|
return NULL;
|
|
|
for (begin = &haystack[needle_last]; begin < haystack_end; ++begin)
|
for (begin = &haystack[needle_last]; begin < haystack_end; ++begin)
|
{
|
{
|
register const char *n = &needle[needle_last];
|
register const char *n = &needle[needle_last];
|
register const char *h = begin;
|
register const char *h = begin;
|
|
|
do
|
do
|
if (*h != *n)
|
if (*h != *n)
|
goto loop; /* continue for loop */
|
goto loop; /* continue for loop */
|
while (--n >= needle && --h >= haystack);
|
while (--n >= needle && --h >= haystack);
|
|
|
return (char *) h;
|
return (char *) h;
|
|
|
loop:;
|
loop:;
|
}
|
}
|
|
|
return NULL;
|
return NULL;
|
}
|
}
|
|
|
|
|
|
|
#endif
|
#endif
|
|
|