Initial revision

This commit is contained in:
eck 1989-05-11 10:09:52 +00:00
parent 0a7c058d01
commit 749c364816
22 changed files with 466 additions and 0 deletions

View file

@ -0,0 +1,21 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
void *
memchr(const void *s, int c, register size_t n)
{
register unsigned char *s1 = (unsigned char *)s;
unsigned char c1 = (unsigned char) c;
while (n > 0) {
n--;
if (*s1++ == c1)
return (void *) --s1;
}
return (void *) NULL;
}

View file

@ -0,0 +1,18 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
int
memcmp(register const void *s1, register const void *s2, size_t n)
{
while (n > 0) {
n--;
if (*s1++ != *s2++)
return *--s1 - *--s2;
}
return 0;
}

View file

@ -0,0 +1,19 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
void *
memcpy(register void *s1, register const void *s2, register size_t n)
{
void *ret = s1;
while (n > 0) {
n--;
*s1++ = *s2++;
}
return ret;
}

View file

@ -0,0 +1,28 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
void *
memmove(register void *s1, register const void *s2, register size_t n)
{
void *ret = s1;
if (s2 <= s1 && s2 + (n-1) >= s1) {
/* overlap, copy backwards */
s1 += n;
s2 += n;
while (n > 0) {
n--;
*--s1 = *--s2;
}
} else
while (n > 0) {
n--;
*s1++ = *s2++;
}
return ret;
}

View file

@ -0,0 +1,19 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
void *
memset(void *s, int c, register size_t n)
{
register void *s1 = s;
while (n > 0) {
n--;
*s1++ = c;
}
return s;
}

View file

@ -0,0 +1,20 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
char *
strcat(register char *s1, register const char *s2)
{
char *ret = s1;
while (*s1++ != '\0')
/* EMPTY */ ;
s1--;
while (*s1++ = *s2++)
/* EMPTY */ ;
return ret;
}

View file

@ -0,0 +1,20 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
char *
strchr(register const char *s, int c)
{
register char c1 = (char) c;
do {
if (*s == c1)
return s;
} while (*s++ != '\0');
return (char *)NULL;
}

View file

@ -0,0 +1,19 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
int
strcmp(register const char *s1, register const char *s2)
{
for(;;) {
if (*s1 != *s2)
return *s1 - *s2;
if (*s1++ == '\0')
return 0;
s2++;
}
}

View file

@ -0,0 +1,20 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
#include <locale.h>
int
strcoll(register const char *s1, register const char *s2)
{
for(;;) {
if (*s1 != *s2)
return *s1 - *s2;
if (*s1++ == '\0')
return 0;
s2++;
}
}

View file

@ -0,0 +1,18 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
char *
strcpy(register char *s1, register const char *s2)
{
char *ret = s1;
while (*s1++ = *s2++)
/* EMPTY */ ;
return ret;
}

View file

@ -0,0 +1,21 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
size_t
strcspn(const char *string, const char *notin)
{
register char *s1, *s2;
for (s1 = string; *s1; s1++) {
for(s2 = notin; *s2 != *s1 && *s2; s2++)
/* EMPTY */ ;
if (*s2)
break;
}
return s1 - string;
}

View file

@ -0,0 +1,18 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
char *
strerror(register int errnum)
{
extern const char *_sys_errlist[];
extern const int _sys_nerr;
if (errnum < 0 || errnum >= _sys_nerr)
return "unknown error";
return _sys_errlist[errnum];
}

View file

@ -0,0 +1,18 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
size_t
strlen(register const char *s)
{
char *org = s;
while (*s++)
/* EMPTY */ ;
return (s - 1) - org;
}

View file

@ -0,0 +1,26 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
char *
strncat(register char *s1, register const char *s2, size_t n)
{
char *ret = s1;
if (n <= 0)
return s1;
while (*s1++)
/* EMPTY */ ;
s1--;
while (*s1++ = *s2++) {
if (--n == 0) {
*s1 = '\0';
break;
}
}
return ret;
}

View file

@ -0,0 +1,21 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
int
strncmp(register const char *s1, register const char *s2, size_t n)
{
while (n > 0) {
n--;
if (*s1 != *s2)
return *s1 - *s2;
if (*s1++ == '\0')
return 0;
s2++;
}
return 0;
}

View file

@ -0,0 +1,23 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
char *
strncpy(register char *s1, register const char *s2, size_t n)
{
char *ret = s1;
while (*s2 && n > 0) {
n--;
*s1++ = *s2++;
}
while (n > 0) {
n--;
*s1++ = '\0';
}
return ret;
}

View file

@ -0,0 +1,22 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
char *
strpbrk(register const char *string, register const char *brk)
{
register char *s1;
while (*string) {
for (s1 = brk; *s1 && *s1 != *string; s1++)
/* EMPTY */ ;
if (*s1)
return string;
string++;
}
return (char *)NULL;
}

View file

@ -0,0 +1,22 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
char *
strrchr(register const char *s, int c)
{
register char *result;
register char c1 = (char) c;
result = (char *)NULL;
do {
if (*s == c1)
result = s;
} while (*s++);
return(result);
}

View file

@ -0,0 +1,21 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
size_t
strspn(const char *string, const char *in)
{
register const char *s1, *s2;
for (s1 = string; *s1; s1++) {
for (s2 = in; *s2 && *s2 != *s1; s2++)
/* EMPTY */ ;
if (*s2 == '\0')
break;
}
return s1 - string;
}

View file

@ -0,0 +1,18 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
char *
strstr(register const char *s, register const char *wanted)
{
int len = strlen(wanted);
while (*s != *wanted || strncmp(s, wanted, len))
if (*s++ == '\0')
return (char *)NULL;
return s;
}

View file

@ -0,0 +1,30 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
char *
strtok(register char *string, const char *separators)
{
register char *s1, *s2;
static char *savestring;
if (!string)
string = savestring;
if (!string)
return (char *)NULL;
if (*(s1 = string + strspn(string, separators)) == '\0') {
savestring = NULL;
return (char *)NULL;
}
if (s2 = strpbrk(s1, separators))
*s2++ = '\0';
savestring = s2;
return s1;
}

View file

@ -0,0 +1,24 @@
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* $Header$ */
#include <string.h>
size_t
strxfrm(register char *s1, register const char *s2, register size_t n)
{
char *save = s2;
while (*s2) {
if (n > 1) {
n--;
*s1++ = *s2++;
} else
s2++;
}
if (n >= 1)
*s1++ = '\0';
return s2 - save;
}