OpenCores
URL https://opencores.org/ocsvn/or1k_old/or1k_old/trunk

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [rc203soc/] [sw/] [uClinux/] [lib/] [string.c] - Diff between revs 1765 and 1782

Only display areas with differences | Details | Blame | View Log

Rev 1765 Rev 1782
/*
/*
 *  linux/lib/string.c
 *  linux/lib/string.c
 *
 *
 *  Copyright (C) 1991, 1992  Linus Torvalds
 *  Copyright (C) 1991, 1992  Linus Torvalds
 */
 */
 
 
/*
/*
 * stupid library routines.. The optimized versions should generally be found
 * stupid library routines.. The optimized versions should generally be found
 * as inline code in <asm-xx/string.h>
 * as inline code in <asm-xx/string.h>
 *
 *
 * These are buggy as well..
 * These are buggy as well..
 */
 */
 
 
#include <linux/types.h>
#include <linux/types.h>
#include <linux/string.h>
#include <linux/string.h>
 
 
char * ___strtok = NULL;
char * ___strtok = NULL;
 
 
#ifndef __HAVE_ARCH_STRCPY
#ifndef __HAVE_ARCH_STRCPY
char * strcpy(char * dest,const char *src)
char * strcpy(char * dest,const char *src)
{
{
        char *tmp = dest;
        char *tmp = dest;
 
 
        while ((*dest++ = *src++) != '\0')
        while ((*dest++ = *src++) != '\0')
                /* nothing */;
                /* nothing */;
        return tmp;
        return tmp;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRNCPY
#ifndef __HAVE_ARCH_STRNCPY
char * strncpy(char * dest,const char *src,size_t count)
char * strncpy(char * dest,const char *src,size_t count)
{
{
        char *tmp = dest;
        char *tmp = dest;
 
 
        while (count-- && (*dest++ = *src++) != '\0')
        while (count-- && (*dest++ = *src++) != '\0')
                /* nothing */;
                /* nothing */;
 
 
        return tmp;
        return tmp;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRCAT
#ifndef __HAVE_ARCH_STRCAT
char * strcat(char * dest, const char * src)
char * strcat(char * dest, const char * src)
{
{
        char *tmp = dest;
        char *tmp = dest;
 
 
        while (*dest)
        while (*dest)
                dest++;
                dest++;
        while ((*dest++ = *src++) != '\0')
        while ((*dest++ = *src++) != '\0')
                ;
                ;
 
 
        return tmp;
        return tmp;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRNCAT
#ifndef __HAVE_ARCH_STRNCAT
char * strncat(char *dest, const char *src, size_t count)
char * strncat(char *dest, const char *src, size_t count)
{
{
        char *tmp = dest;
        char *tmp = dest;
 
 
        if (count) {
        if (count) {
                while (*dest)
                while (*dest)
                        dest++;
                        dest++;
                while ((*dest++ = *src++)) {
                while ((*dest++ = *src++)) {
                        if (--count == 0) {
                        if (--count == 0) {
                                *dest = '\0';
                                *dest = '\0';
                                break;
                                break;
                        }
                        }
                }
                }
        }
        }
 
 
        return tmp;
        return tmp;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRCMP
#ifndef __HAVE_ARCH_STRCMP
int strcmp(const char * cs,const char * ct)
int strcmp(const char * cs,const char * ct)
{
{
        register signed char __res;
        register signed char __res;
 
 
        while (1) {
        while (1) {
                if ((__res = *cs - *ct++) != 0 || !*cs++)
                if ((__res = *cs - *ct++) != 0 || !*cs++)
                        break;
                        break;
        }
        }
 
 
        return __res;
        return __res;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRNCMP
#ifndef __HAVE_ARCH_STRNCMP
int strncmp(const char * cs,const char * ct,size_t count)
int strncmp(const char * cs,const char * ct,size_t count)
{
{
        register signed char __res = 0;
        register signed char __res = 0;
 
 
        while (count) {
        while (count) {
                if ((__res = *cs - *ct++) != 0 || !*cs++)
                if ((__res = *cs - *ct++) != 0 || !*cs++)
                        break;
                        break;
                count--;
                count--;
        }
        }
 
 
        return __res;
        return __res;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRCHR
#ifndef __HAVE_ARCH_STRCHR
char * strchr(const char * s, int c)
char * strchr(const char * s, int c)
{
{
        for(; *s != (char) c; ++s)
        for(; *s != (char) c; ++s)
                if (*s == '\0')
                if (*s == '\0')
                        return NULL;
                        return NULL;
        return (char *) s;
        return (char *) s;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRRCHR
#ifndef __HAVE_ARCH_STRRCHR
char * strrchr(const char * s, int c)
char * strrchr(const char * s, int c)
{
{
       const char *p = s + strlen(s);
       const char *p = s + strlen(s);
       do {
       do {
           if (*p == (char)c)
           if (*p == (char)c)
               return (char *)p;
               return (char *)p;
       } while (--p >= s);
       } while (--p >= s);
       return NULL;
       return NULL;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRLEN
#ifndef __HAVE_ARCH_STRLEN
size_t strlen(const char * s)
size_t strlen(const char * s)
{
{
        const char *sc;
        const char *sc;
 
 
        for (sc = s; *sc != '\0'; ++sc)
        for (sc = s; *sc != '\0'; ++sc)
                /* nothing */;
                /* nothing */;
        return sc - s;
        return sc - s;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRNLEN
#ifndef __HAVE_ARCH_STRNLEN
size_t strnlen(const char * s, size_t count)
size_t strnlen(const char * s, size_t count)
{
{
        const char *sc;
        const char *sc;
 
 
        for (sc = s; count-- && *sc != '\0'; ++sc)
        for (sc = s; count-- && *sc != '\0'; ++sc)
                /* nothing */;
                /* nothing */;
        return sc - s;
        return sc - s;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRSPN
#ifndef __HAVE_ARCH_STRSPN
size_t strspn(const char *s, const char *accept)
size_t strspn(const char *s, const char *accept)
{
{
        const char *p;
        const char *p;
        const char *a;
        const char *a;
        size_t count = 0;
        size_t count = 0;
 
 
        for (p = s; *p != '\0'; ++p) {
        for (p = s; *p != '\0'; ++p) {
                for (a = accept; *a != '\0'; ++a) {
                for (a = accept; *a != '\0'; ++a) {
                        if (*p == *a)
                        if (*p == *a)
                                break;
                                break;
                }
                }
                if (*a == '\0')
                if (*a == '\0')
                        return count;
                        return count;
                ++count;
                ++count;
        }
        }
 
 
        return count;
        return count;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRPBRK
#ifndef __HAVE_ARCH_STRPBRK
char * strpbrk(const char * cs,const char * ct)
char * strpbrk(const char * cs,const char * ct)
{
{
        const char *sc1,*sc2;
        const char *sc1,*sc2;
 
 
        for( sc1 = cs; *sc1 != '\0'; ++sc1) {
        for( sc1 = cs; *sc1 != '\0'; ++sc1) {
                for( sc2 = ct; *sc2 != '\0'; ++sc2) {
                for( sc2 = ct; *sc2 != '\0'; ++sc2) {
                        if (*sc1 == *sc2)
                        if (*sc1 == *sc2)
                                return (char *) sc1;
                                return (char *) sc1;
                }
                }
        }
        }
        return NULL;
        return NULL;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRTOK
#ifndef __HAVE_ARCH_STRTOK
char * strtok(char * s,const char * ct)
char * strtok(char * s,const char * ct)
{
{
        char *sbegin, *send;
        char *sbegin, *send;
 
 
        sbegin  = s ? s : ___strtok;
        sbegin  = s ? s : ___strtok;
        if (!sbegin) {
        if (!sbegin) {
                return NULL;
                return NULL;
        }
        }
        sbegin += strspn(sbegin,ct);
        sbegin += strspn(sbegin,ct);
        if (*sbegin == '\0') {
        if (*sbegin == '\0') {
                ___strtok = NULL;
                ___strtok = NULL;
                return( NULL );
                return( NULL );
        }
        }
        send = strpbrk( sbegin, ct);
        send = strpbrk( sbegin, ct);
        if (send && *send != '\0')
        if (send && *send != '\0')
                *send++ = '\0';
                *send++ = '\0';
        ___strtok = send;
        ___strtok = send;
        return (sbegin);
        return (sbegin);
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_MEMSET
#ifndef __HAVE_ARCH_MEMSET
void * memset(void * s,int c,size_t count)
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;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_BCOPY
#ifndef __HAVE_ARCH_BCOPY
char * bcopy(const char * src, char * dest, int count)
char * bcopy(const char * src, char * dest, int count)
{
{
        char *tmp = dest;
        char *tmp = dest;
 
 
        while (count--)
        while (count--)
                *tmp++ = *src++;
                *tmp++ = *src++;
 
 
        return dest;
        return dest;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_MEMCPY
#ifndef __HAVE_ARCH_MEMCPY
void * memcpy(void * dest,const void *src,size_t count)
void * memcpy(void * dest,const void *src,size_t count)
{
{
        char *tmp = (char *) dest, *s = (char *) src;
        char *tmp = (char *) dest, *s = (char *) src;
 
 
        while (count--)
        while (count--)
                *tmp++ = *s++;
                *tmp++ = *s++;
 
 
        return dest;
        return dest;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_MEMMOVE
#ifndef __HAVE_ARCH_MEMMOVE
void * memmove(void * dest,const void *src,size_t count)
void * memmove(void * dest,const void *src,size_t count)
{
{
        char *tmp, *s;
        char *tmp, *s;
 
 
        if (dest <= src) {
        if (dest <= src) {
                tmp = (char *) dest;
                tmp = (char *) dest;
                s = (char *) src;
                s = (char *) src;
                while (count--)
                while (count--)
                        *tmp++ = *s++;
                        *tmp++ = *s++;
                }
                }
        else {
        else {
                tmp = (char *) dest + count;
                tmp = (char *) dest + count;
                s = (char *) src + count;
                s = (char *) src + count;
                while (count--)
                while (count--)
                        *--tmp = *--s;
                        *--tmp = *--s;
                }
                }
 
 
        return dest;
        return dest;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_MEMCMP
#ifndef __HAVE_ARCH_MEMCMP
int memcmp(const void * cs,const void * ct,size_t count)
int memcmp(const void * cs,const void * ct,size_t count)
{
{
        const unsigned char *su1, *su2;
        const unsigned char *su1, *su2;
        signed char res = 0;
        signed char res = 0;
 
 
        for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
        for( su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--)
                if ((res = *su1 - *su2) != 0)
                if ((res = *su1 - *su2) != 0)
                        break;
                        break;
        return res;
        return res;
}
}
#endif
#endif
 
 
/*
/*
 * find the first occurrence of byte 'c', or 1 past the area if none
 * find the first occurrence of byte 'c', or 1 past the area if none
 */
 */
#ifndef __HAVE_ARCH_MEMSCAN
#ifndef __HAVE_ARCH_MEMSCAN
void * memscan(void * addr, int c, size_t size)
void * memscan(void * addr, int c, size_t size)
{
{
        unsigned char * p = (unsigned char *) addr;
        unsigned char * p = (unsigned char *) addr;
 
 
        while (size) {
        while (size) {
                if (*p == c)
                if (*p == c)
                        return (void *) p;
                        return (void *) p;
                p++;
                p++;
                size--;
                size--;
        }
        }
        return (void *) p;
        return (void *) p;
}
}
#endif
#endif
 
 
#ifndef __HAVE_ARCH_STRSTR
#ifndef __HAVE_ARCH_STRSTR
char * strstr(const char * s1,const char * s2)
char * strstr(const char * s1,const char * s2)
{
{
        int l1, l2;
        int l1, l2;
 
 
        l2 = strlen(s2);
        l2 = strlen(s2);
        if (!l2)
        if (!l2)
                return (char *) s1;
                return (char *) s1;
        l1 = strlen(s1);
        l1 = strlen(s1);
        while (l1 >= l2) {
        while (l1 >= l2) {
                l1--;
                l1--;
                if (!memcmp(s1,s2,l2))
                if (!memcmp(s1,s2,l2))
                        return (char *) s1;
                        return (char *) s1;
                s1++;
                s1++;
        }
        }
        return NULL;
        return NULL;
}
}
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.