diff --git a/lang/cem/libcc.ansi/string/.distr b/lang/cem/libcc.ansi/string/.distr new file mode 100644 index 000000000..b59e61d48 --- /dev/null +++ b/lang/cem/libcc.ansi/string/.distr @@ -0,0 +1,24 @@ +LIST +Makefile +memchr.c +memcmp.c +memcpy.c +memmove.c +memset.c +strcat.c +strchr.c +strcmp.c +strcoll.c +strcpy.c +strcspn.c +strerror.c +strlen.c +strncat.c +strncmp.c +strncpy.c +strpbrk.c +strrchr.c +strspn.c +strstr.c +strtok.c +strxfrm.c diff --git a/lang/cem/libcc.ansi/string/LIST b/lang/cem/libcc.ansi/string/LIST index 796c99208..5f594fd11 100644 --- a/lang/cem/libcc.ansi/string/LIST +++ b/lang/cem/libcc.ansi/string/LIST @@ -1,4 +1,3 @@ -libs memchr.c memcmp.c memcpy.c diff --git a/lang/cem/libcc.ansi/string/Makefile b/lang/cem/libcc.ansi/string/Makefile new file mode 100644 index 000000000..4bd90086f --- /dev/null +++ b/lang/cem/libcc.ansi/string/Makefile @@ -0,0 +1,35 @@ +CFLAGS=-L -LIB + +.SUFFIXES: .o .e .c + +.e.o: + $(CC) $(CFLAGS) -c -o $@ $*.e + +clean: + rm -rf memchr.o memcmp.o memcpy.o memmove.o memset.o strcat.o \ + strchr.o strcmp.o strcoll.o strcpy.o strcspn.o strerror.o \ + strncat.o strncpy.o strrchr.o strstr.o strlen.o strtok.o \ + strpbrk.o strspn.o strncmp.o strxfrm.o OLIST + +memchr.o: +memcmp.o: +memcpy.o: +memmove.o: +memset.o: +strcat.o: +strchr.o: +strcmp.o: +strcoll.o: +strcpy.o: +strcspn.o: +strerror.o: +strncat.o: +strncpy.o: +strrchr.o: +strstr.o: +strlen.o: +strtok.o: +strpbrk.o: +strspn.o: +strncmp.o: +strxfrm.o: diff --git a/lang/cem/libcc.ansi/string/memchr.c b/lang/cem/libcc.ansi/string/memchr.c index f5dbd0a1b..b91644a29 100644 --- a/lang/cem/libcc.ansi/string/memchr.c +++ b/lang/cem/libcc.ansi/string/memchr.c @@ -9,13 +9,13 @@ void * memchr(const void *s, int c, register size_t n) { - register unsigned char *s1 = (unsigned char *)s; + register const unsigned char *s1 = s; unsigned char c1 = (unsigned char) c; while (n > 0) { n--; if (*s1++ == c1) - return (void *) --s1; + return (void *) (s1 - 1); } - return (void *) NULL; + return NULL; } diff --git a/lang/cem/libcc.ansi/string/memcmp.c b/lang/cem/libcc.ansi/string/memcmp.c index 0f9bd84ee..8ae481b33 100644 --- a/lang/cem/libcc.ansi/string/memcmp.c +++ b/lang/cem/libcc.ansi/string/memcmp.c @@ -7,12 +7,14 @@ #include int -memcmp(register const void *s1, register const void *s2, size_t n) +memcmp(const void *s1, const void *s2, size_t n) { + register const char *p1 = s1, *p2 = s2; + while (n > 0) { n--; - if (*s1++ != *s2++) - return *--s1 - *--s2; + if (*p1++ != *p2++) + return *--p1 - *--p2; } return 0; } diff --git a/lang/cem/libcc.ansi/string/memcpy.c b/lang/cem/libcc.ansi/string/memcpy.c index a36010ac8..11b27b0c7 100644 --- a/lang/cem/libcc.ansi/string/memcpy.c +++ b/lang/cem/libcc.ansi/string/memcpy.c @@ -9,11 +9,13 @@ void * memcpy(register void *s1, register const void *s2, register size_t n) { - void *ret = s1; + register char *p1 = s1; + register const char *p2 = s2; + while (n > 0) { n--; - *s1++ = *s2++; + *p1++ = *p2++; } - return ret; + return s1; } diff --git a/lang/cem/libcc.ansi/string/memmove.c b/lang/cem/libcc.ansi/string/memmove.c index baa45bcfe..33c7f5b74 100644 --- a/lang/cem/libcc.ansi/string/memmove.c +++ b/lang/cem/libcc.ansi/string/memmove.c @@ -7,22 +7,23 @@ #include void * -memmove(register void *s1, register const void *s2, register size_t n) +memmove(void *s1, const void *s2, register size_t n) { - void *ret = s1; + register char *p1 = s1; + register const char *p2 = s2; - if (s2 <= s1 && s2 + (n-1) >= s1) { + if (p2 <= p1 && p2 + (n-1) >= p1) { /* overlap, copy backwards */ - s1 += n; - s2 += n; + p1 += n; + p2 += n; while (n > 0) { n--; - *--s1 = *--s2; + *--p1 = *--p2; } } else while (n > 0) { n--; - *s1++ = *s2++; + *p1++ = *p2++; } - return ret; + return s1; } diff --git a/lang/cem/libcc.ansi/string/memset.c b/lang/cem/libcc.ansi/string/memset.c index 6fa8b9785..469de4f16 100644 --- a/lang/cem/libcc.ansi/string/memset.c +++ b/lang/cem/libcc.ansi/string/memset.c @@ -9,7 +9,7 @@ void * memset(void *s, int c, register size_t n) { - register void *s1 = s; + register char *s1 = s; while (n > 0) { n--; diff --git a/lang/cem/libcc.ansi/string/strchr.c b/lang/cem/libcc.ansi/string/strchr.c index 1a14e672b..979f4354d 100644 --- a/lang/cem/libcc.ansi/string/strchr.c +++ b/lang/cem/libcc.ansi/string/strchr.c @@ -13,7 +13,7 @@ strchr(register const char *s, int c) do { if (*s == c1) - return s; + return (char *)s; } while (*s++ != '\0'); return (char *)NULL; diff --git a/lang/cem/libcc.ansi/string/strcspn.c b/lang/cem/libcc.ansi/string/strcspn.c index 8db4d1a33..fbdc1d022 100644 --- a/lang/cem/libcc.ansi/string/strcspn.c +++ b/lang/cem/libcc.ansi/string/strcspn.c @@ -9,7 +9,7 @@ size_t strcspn(const char *string, const char *notin) { - register char *s1, *s2; + register const char *s1, *s2; for (s1 = string; *s1; s1++) { for(s2 = notin; *s2 != *s1 && *s2; s2++) diff --git a/lang/cem/libcc.ansi/string/strerror.c b/lang/cem/libcc.ansi/string/strerror.c index 7bb41b503..a5841c7c8 100644 --- a/lang/cem/libcc.ansi/string/strerror.c +++ b/lang/cem/libcc.ansi/string/strerror.c @@ -14,5 +14,5 @@ strerror(register int errnum) if (errnum < 0 || errnum >= _sys_nerr) return "unknown error"; - return _sys_errlist[errnum]; + return (char *)_sys_errlist[errnum]; } diff --git a/lang/cem/libcc.ansi/string/strlen.c b/lang/cem/libcc.ansi/string/strlen.c index bd4cb81bc..ca8f7d838 100644 --- a/lang/cem/libcc.ansi/string/strlen.c +++ b/lang/cem/libcc.ansi/string/strlen.c @@ -9,7 +9,7 @@ size_t strlen(register const char *s) { - char *org = s; + const char *org = s; while (*s++) /* EMPTY */ ; diff --git a/lang/cem/libcc.ansi/string/strpbrk.c b/lang/cem/libcc.ansi/string/strpbrk.c index a0c4cdb40..5f08731bb 100644 --- a/lang/cem/libcc.ansi/string/strpbrk.c +++ b/lang/cem/libcc.ansi/string/strpbrk.c @@ -9,13 +9,13 @@ char * strpbrk(register const char *string, register const char *brk) { - register char *s1; + register const char *s1; while (*string) { for (s1 = brk; *s1 && *s1 != *string; s1++) /* EMPTY */ ; if (*s1) - return string; + return (char *)string; string++; } return (char *)NULL; diff --git a/lang/cem/libcc.ansi/string/strrchr.c b/lang/cem/libcc.ansi/string/strrchr.c index 1bf6cea43..e98d8d7cf 100644 --- a/lang/cem/libcc.ansi/string/strrchr.c +++ b/lang/cem/libcc.ansi/string/strrchr.c @@ -9,7 +9,7 @@ char * strrchr(register const char *s, int c) { - register char *result; + register const char *result; register char c1 = (char) c; result = (char *)NULL; @@ -18,5 +18,5 @@ strrchr(register const char *s, int c) result = s; } while (*s++); - return(result); + return (char *)result; } diff --git a/lang/cem/libcc.ansi/string/strstr.c b/lang/cem/libcc.ansi/string/strstr.c index 18d7ae8fd..4c2b23444 100644 --- a/lang/cem/libcc.ansi/string/strstr.c +++ b/lang/cem/libcc.ansi/string/strstr.c @@ -11,8 +11,9 @@ strstr(register const char *s, register const char *wanted) { int len = strlen(wanted); + if (len == 0) return (char *)s; while (*s != *wanted || strncmp(s, wanted, len)) if (*s++ == '\0') return (char *)NULL; - return s; + return (char *)s; } diff --git a/lang/cem/libcc.ansi/string/strxfrm.c b/lang/cem/libcc.ansi/string/strxfrm.c index 3ec1b3acb..92e0c76c0 100644 --- a/lang/cem/libcc.ansi/string/strxfrm.c +++ b/lang/cem/libcc.ansi/string/strxfrm.c @@ -9,7 +9,7 @@ size_t strxfrm(register char *s1, register const char *s2, register size_t n) { - char *save = s2; + const char *save = s2; while (*s2) { if (n > 1) {