From: Alan Cox Date: Wed, 20 May 2015 13:11:41 +0000 (+0100) Subject: libc: remove 3 clause BSD code and replace from dLibs 1.20 X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=ac705355647063e70afd9e4e81a43eafa35cc391;p=FUZIX.git libc: remove 3 clause BSD code and replace from dLibs 1.20 --- diff --git a/Library/libs/memcmp.c b/Library/libs/memcmp.c index e1fb2095..67a61592 100644 --- a/Library/libs/memcmp.c +++ b/Library/libs/memcmp.c @@ -1,22 +1,18 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * This file is licensed under the terms of the 3-clause BSD open source - * license. - */ - #include -int -memcmp(const void *s1, const void *s2, size_t n) +/* ANSIfied from dLibs 1.2 and handling of 0 length compare done as per + convention (equality) */ + +int memcmp(const void *mem1, const void *mem2, size_t len) { - register const unsigned char *p1 = s1, *p2 = s2; + const signed char *p1 = mem1, *p2 = mem2; + + if (!len) + return 0; - if (n) { - n++; - while (--n > 0) { - if (*p1++ == *p2++) continue; - return *--p1 - *--p2; - } + while (--len && *p1 == *p2) { + p1++; + p2++; } - return 0; + return *p1 - *p2; } diff --git a/Library/libs/memcpy.c b/Library/libs/memcpy.c index 5547d083..fd403043 100644 --- a/Library/libs/memcpy.c +++ b/Library/libs/memcpy.c @@ -1,23 +1,10 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * This file is licensed under the terms of the 3-clause BSD open source - * license. - */ +#include -#include - -void * -memcpy(void *s1, const void *s2, register size_t n) +void *memcpy(void *dest, const void *src, size_t len) { - register char *p1 = s1; - register const char *p2 = s2; - - - if (n) { - n++; - while (--n > 0) { - *p1++ = *p2++; - } - } - return s1; + uint8_t *dp = dest; + uint8_t *sp = src; + while(len-- > 0) + *dp++=*sp++; + return dest; } diff --git a/Library/libs/memmove.c b/Library/libs/memmove.c index f3e12d89..1b16218b 100644 --- a/Library/libs/memmove.c +++ b/Library/libs/memmove.c @@ -1,32 +1,18 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * This file is licensed under the terms of the 3-clause BSD open source - * license. - */ +/* From dLibs 1.20 but ANSIfied */ -#include - -void * -memmove(void *s1, const void *s2, register size_t n) +void *memmove(void *dest, const void *source, size_t len) { - register char *p1 = s1; - register const char *p2 = s2; - - if (n>0) { - if (p2 <= p1 && p2 + n > p1) { - /* overlap, copy backwards */ - p1 += n; - p2 += n; - n++; - while (--n > 0) { - *--p1 = *--p2; - } - } else { - n++; - while (--n > 0) { - *p1++ = *p2++; - } - } + uint8_t *dp = dest; + uint8_t *sp = src; + + if (sp < dp) { + dp += len; + sp += len; + while(len--) + *--dp = *--sp; + } else { + while(len--) + *dp++ = *sp++; } - return s1; + return dest; } diff --git a/Library/libs/memset.c b/Library/libs/memset.c index 34ec4f45..5c837bbc 100644 --- a/Library/libs/memset.c +++ b/Library/libs/memset.c @@ -1,20 +1,10 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * This file is licensed under the terms of the 3-clause BSD open source - * license. - */ -#include +#include -void * -memset(void *s, register int c, register size_t n) +void *memset(void *dest, int data, size_t len) { - register char *s1 = s; + char *p = dest; + char v = (char)data; - if (n>0) { - n++; - while (--n > 0) { - *s1++ = c; - } - } - return s; + while(len--) + *p++ = v; } diff --git a/Library/libs/strlen.c b/Library/libs/strlen.c index 665cd494..568ce561 100644 --- a/Library/libs/strlen.c +++ b/Library/libs/strlen.c @@ -1,18 +1,9 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * This file is licensed under the terms of the 3-clause BSD open source - * license. - */ +#include -#include - -size_t -strlen(const char *org) +size_t strlen(const char *t) { - register const char *s = org; - - while (*s++) - /* EMPTY */ ; - - return --s - org; + size_t ct = 0; + while (*t++) + ct++; + return ct; } diff --git a/Library/libs/strncmp.c b/Library/libs/strncmp.c index 0c296c78..5de303d8 100644 --- a/Library/libs/strncmp.c +++ b/Library/libs/strncmp.c @@ -1,26 +1,11 @@ -/* - * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands. - * This file is licensed under the terms of the 3-clause BSD open source - * license. - */ - #include -int -strncmp(register const char *s1, register const char *s2, register size_t n) +/* ANSIfied from dLibs 1.2 */ + +int strncmp(const char *str1, const char *str2, size_t limit) { - if (n) { - do { - if (*s1 != *s2++) - break; - if (*s1++ == '\0') - return 0; - } while (--n > 0); - if (n > 0) { - if (*s1 == '\0') return -1; - if (*--s2 == '\0') return 1; - return (unsigned char) *s1 - (unsigned char) *s2; - } - } - return 0; + for(; ((--limit) && (*str1 == *str2)); ++str1, ++str2) + if (*str1 == '\0') + return 0; + return *str1 - *str2; } diff --git a/Library/libs/strnlen.c b/Library/libs/strnlen.c index 3c23d84e..fa61f4a2 100644 --- a/Library/libs/strnlen.c +++ b/Library/libs/strnlen.c @@ -3,7 +3,6 @@ size_t strnlen(const char *t, size_t n) { size_t ct = 0; - while (*t++ && ct++ < n) - t++; + while (*t++ && ct++ < n); return ct; }