fixed some bugs, added LIST, Makefile & .distr

This commit is contained in:
eck 1989-12-18 16:02:55 +00:00
parent 8a409311da
commit dc2dd991c6
16 changed files with 93 additions and 29 deletions

View file

@ -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

View file

@ -1,4 +1,3 @@
libs
memchr.c
memcmp.c
memcpy.c

View file

@ -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:

View file

@ -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;
}

View file

@ -7,12 +7,14 @@
#include <string.h>
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;
}

View file

@ -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;
}

View file

@ -7,22 +7,23 @@
#include <string.h>
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;
}

View file

@ -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--;

View file

@ -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;

View file

@ -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++)

View file

@ -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];
}

View file

@ -9,7 +9,7 @@
size_t
strlen(register const char *s)
{
char *org = s;
const char *org = s;
while (*s++)
/* EMPTY */ ;

View file

@ -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;

View file

@ -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;
}

View file

@ -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;
}

View file

@ -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) {