Commit 59409d99 authored by Alessandro Rubini's avatar Alessandro Rubini

libc-functions: use uClibc code

Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent a82a8054
/* /*
* Alessandro Rubini for CERN, 2011 -- GPL 2 or later (it includes u-boot code) * All code from uClibc-0.9.32. LGPL V2.1
* (FIXME: turn to LGPL by using uclibc or equivalent -- avoid rewriting :)
*/ */
#include <ppsi/lib.h> #include <ppsi/lib.h>
...@@ -11,54 +10,62 @@ int puts(const char *s) ...@@ -11,54 +10,62 @@ int puts(const char *s)
return 0; return 0;
} }
size_t strnlen(const char *s, size_t maxlen) /* libc/string/strnlen.c */
size_t strnlen(const char *s, size_t max)
{ {
int len = 0; register const char *p = s;
while (*(s++))
len++; while (max && *p) {
return len; ++p;
--max;
}
return p - s;
} }
void *memcpy(void *dest, const void *src, size_t count) /* libc/string/memcpy.c */
void *memcpy(void *s1, const void *s2, size_t n)
{ {
/* from u-boot-1.1.2 */ register char *r1 = s1;
char *tmp = (char *) dest, *s = (char *) src; register const char *r2 = s2;
while (count--)
*tmp++ = *s++;
return dest; while (n) {
*r1++ = *r2++;
--n;
}
return s1;
} }
int memcmp(const void *cs, const void *ct, size_t count) /* libc/string/memcmp.c */
int memcmp(const void *s1, const void *s2, size_t n)
{ {
/* from u-boot-1.1.2 */ register const unsigned char *r1 = s1;
const unsigned char *su1, *su2; register const unsigned char *r2 = s2;
int res = 0; int r = 0;
for (su1 = cs, su2 = ct; 0 < count; ++su1, ++su2, count--) while (n-- && ((r = ((int)(*r1++)) - *r2++) == 0))
if ((res = *su1 - *su2) != 0) ;
break; return r;
return res;
} }
void *memset(void *s, int c, size_t count) /* libc/string/memset.c */
void *memset(void *s, int c, size_t n)
{ {
/* from u-boot-1.1.2 */ register unsigned char *p = s;
char *xs = (char *) s;
while (count--)
*xs++ = c;
while (n) {
*p++ = (unsigned char) c;
--n;
}
return s; return s;
} }
char *strcpy(char *dest, const char *src)
/* libc/string/strcpy.c */
char *strcpy(char *s1, const char *s2)
{ {
/* from u-boot-1.1.2 */ register char *s = s1;
char *tmp = dest;
while ((*dest++ = *src++) != '\0') while ( (*s++ = *s2++) != 0 )
/* nothing */; ;
return tmp; return s1;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment