add directory gnu

This commit is contained in:
gohigh
2024-02-19 00:24:47 -05:00
parent 32616db5a4
commit a40f4cadb0
5086 changed files with 1860970 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
# Copyright (C) 1991, 1992 Free Software Foundation, Inc.
# This file is part of the GNU C Library.
# The GNU C Library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public License as
# published by the Free Software Foundation; either version 2 of the
# License, or (at your option) any later version.
# The GNU C Library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Library General Public License for more details.
# You should have received a copy of the GNU Library General Public
# License along with the GNU C Library; see the file COPYING.LIB. If
# not, write to the Free Software Foundation, Inc., 675 Mass Ave,
# Cambridge, MA 02139, USA.
#
# Sub-makefile for string portion of library.
#
subdir := string
headers := string.h strings.h bstring.h memory.h endian.h
routines := strcat strchr strcmp strcoll strcpy strcspn strdup \
strerror strlen strncat strncmp strncpy strpbrk \
strrchr strsignal strspn strstr strtok strxfrm \
__memccpy memchr memcmp memmove memset \
bcopy bzero ffs stpcpy strcasecmp \
rindex index bcmp memccpy memcpy wordcopy
tests := tester testcopy
distribute := memcopy.h
include ../Rules

View File

@@ -0,0 +1,29 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <bstring.h>
#undef bcmp
#include <gnu-stabs.h>
function_alias(bcmp, memcmp, int, (s1, s2, n),
DEFUN(bcmp, (s1, s2, n),
CONST PTR s1 AND CONST PTR s2 AND size_t n))

View File

@@ -0,0 +1,45 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
/* Compatibility with BSD bstring(3). */
#ifndef _BSTRING_H
#define _BSTRING_H 1
#include <features.h>
#define __need_size_t
#include <stddef.h>
/* Copy N bytes of SRC to DEST. */
extern void EXFUN(bcopy, (CONST PTR __src, PTR __dest, size_t __n));
/* Set N bytes of S to 0. */
extern void EXFUN(bzero, (PTR __s, size_t __n));
/* Compare N bytes of S1 and S2. */
extern int EXFUN(bcmp, (CONST PTR __s1, CONST PTR __s2, size_t __n));
/* Return the position of the first bit set in I, or 0 if none are set.
The least-significant bit is position 1, the most-significant 32. */
extern int EXFUN(ffs, (int __i));
#if defined(__GNUC__) && defined(__OPTIMIZE__)
#define ffs() __builtin_ffs()
#endif /* GCC and optimizing. */
#endif /* bstring.h */

View File

@@ -0,0 +1,29 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <strings.h>
#include <bstring.h>
#undef index
#include <gnu-stabs.h>
function_alias(index, strchr, char *, (s, c),
DEFUN(index, (s, c), CONST char *s AND int c))

View File

@@ -0,0 +1,28 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#undef memccpy
#include <gnu-stabs.h>
function_alias(memccpy, __memccpy, PTR, (dest, src, c, n),
DEFUN(memccpy, (dest, src, c, n),
PTR dest AND CONST PTR src AND int c AND size_t n))

View File

@@ -0,0 +1,34 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
/*
* SVID
*/
#ifndef _MEMORY_H
#define _MEMORY_H 1
#include <features.h>
#ifndef _STRING_H
#include <string.h>
#endif /* string.h */
#endif /* memory.h */

View File

@@ -0,0 +1,28 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <string.h>
#include <strings.h>
#undef rindex
#include <gnu-stabs.h>
function_alias(rindex, strrchr, char *, (s, c),
DEFUN(rindex, (s, c), CONST char *s AND int c))

View File

@@ -0,0 +1,70 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <localeinfo.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
/* Compare S1 and S2, returning less than, equal to or
greater than zero if the collated form of S1 is lexiographically
less than, equal to or greater than the collated form of S2. */
int
DEFUN(strcoll, (s1, s2), CONST char *s1 AND CONST char *s2)
{
if (_collate_info == NULL || _collate_info->values == NULL)
return strcmp(s1, s2);
else
{
CONST unsigned char *CONST values = _collate_info->values;
CONST unsigned char *CONST offsets = _collate_info->offsets;
while (*s1 != '\0' && *s2 != '\0')
{
CONST unsigned char c1 = *s1++, c2 = *s2++;
CONST unsigned char v1 = values[c1], v2 = values[c2];
CONST unsigned char o1 = offsets[c1], o2 = offsets[c2];
if (v1 == UCHAR_MAX && o1 == 0)
/* This is a non-collating element. Skip it. */
--s2;
else if (v2 == UCHAR_MAX && o2 == 0)
--s1;
else if (v1 == UCHAR_MAX && o1 == CHAR_MAX)
{
/* This element collates lower than anything else. */
if (v2 != UCHAR_MAX || o2 != CHAR_MAX)
return -1;
}
else if (v2 == UCHAR_MAX && o2 == CHAR_MAX)
return 1;
else if (v1 != v2)
return v1 - v2;
else if (o1 != o2)
return o1 - o2;
}
if (*s1 == '\0')
return *s2 == '\0' ? 0 : -1;
else if (*s2 == '\0')
return 1;
return 0;
}
}

View File

@@ -0,0 +1,38 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
/* Duplicate S, returning an identical malloc'd string. */
char *
DEFUN(strdup, (s), CONST char *s)
{
size_t len = strlen(s) + 1;
PTR new = malloc(len);
if (new == NULL)
return NULL;
memcpy(new, (PTR) s, len);
return (char *) new;
}

View File

@@ -0,0 +1,50 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stdio.h>
#include <string.h>
#ifndef HAVE_GNU_LD
#define _sys_errlist sys_errlist
#define _sys_nerr sys_nerr
#endif
/* Defined in stdio/sys_errlist.c. */
extern CONST char *CONST _sys_errlist[];
extern CONST int _sys_nerr;
/* Return a string descibing the errno code in ERRNUM.
The storage is good only until the next call to strerror.
Writing to the storage causes undefined behavior. */
char *
DEFUN(strerror, (errnum), int errnum)
{
if (errnum < 0 || errnum > _sys_nerr)
{
static char unknown_error[] = "Unknown error 000000000000000000";
static char fmt[] = "Unknown error %d";
size_t len = sprintf(unknown_error, fmt, errnum);
if (len < sizeof(fmt) - 2)
return NULL;
unknown_error[len - 1] = '\0';
return unknown_error;
}
return (char *) _sys_errlist[errnum];
}

View File

@@ -0,0 +1,135 @@
/* Copyright (C) 1991, 1992 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
/*
* ANSI Standard: 4.11 STRING HANDLING <string.h>
*/
#ifndef _STRING_H
#define _STRING_H 1
#include <features.h>
/* Get size_t and NULL from <stddef.h>. */
#define __need_size_t
#define __need_NULL
#include <stddef.h>
/* Copy N bytes of SRC to DEST. */
extern PTR EXFUN(memcpy, (PTR __dest, CONST PTR __src, size_t __n));
/* Copy N bytes of SRC to DEST, guaranteeing
correct behavior for overlapping strings. */
extern PTR EXFUN(memmove, (PTR __dest, CONST PTR __src, size_t __n));
/* Copy no more than N bytes of SRC to DEST, stopping when C is found.
Return the position in DEST one byte past where C was copied,
or NULL if C was not found in the first N bytes of SRC. */
extern PTR EXFUN(__memccpy, (PTR __dest, CONST PTR __src,
int __c, size_t __n));
#ifdef __USE_SVID
extern PTR EXFUN(memccpy, (PTR __dest, CONST PTR __src,
int __c, size_t __n));
#ifdef __OPTIMIZE__
#define memccpy(dest, src, c, n) __memccpy((dest), (src), (c), (n))
#endif /* Optimizing. */
#endif /* SVID. */
/* Set N bytes of S to C. */
extern PTR EXFUN(memset, (PTR __s, int __c, size_t __n));
/* Compare N bytes of S1 and S2. */
extern int EXFUN(memcmp, (CONST PTR __s1, CONST PTR __s2, size_t __n));
/* Search N bytes of S for C. */
extern PTR EXFUN(memchr, (CONST PTR __s, int __c, size_t __n));
/* Copy SRC to DEST. */
extern char *EXFUN(strcpy, (char *__dest, CONST char *__src));
/* Copy no more than N characters of SRC to DEST. */
extern char *EXFUN(strncpy, (char *__dest, CONST char *__src, size_t __n));
/* Append SRC onto DEST. */
extern char *EXFUN(strcat, (char *__src, CONST char *__dest));
/* Append no more than N characters from SRC onto DEST. */
extern char *EXFUN(strncat, (char *__dest, CONST char *__src, size_t __n));
/* Compare S1 and S2. */
extern int EXFUN(strcmp, (CONST char *__s1, CONST char *__s2));
/* Compare N characters of S1 and S2. */
extern int EXFUN(strncmp, (CONST char *__s1, CONST char *__s2, size_t __n));
/* Compare the collated forms of S1 and S2. */
extern int EXFUN(strcoll, (CONST char *__s1, CONST char *__s2));
/* Put a transformation of SRC into no more than N bytes of DEST. */
extern size_t EXFUN(strxfrm, (char *__dest, CONST char *__src, size_t __n));
#ifdef __USE_SVID
/* Duplicate S, returning an identical malloc'd string. */
extern char *EXFUN(strdup, (CONST char *__s));
#endif
/* Find the first occurrence of C in S. */
extern char *EXFUN(strchr, (CONST char *__s, int __c));
/* Find the last occurrence of C in S. */
extern char *EXFUN(strrchr, (CONST char *__s, int __c));
/* Return the length of the initial segment of S which
consists entirely of characters not in REJECT. */
extern size_t EXFUN(strcspn, (CONST char *__s, CONST char *__reject));
/* Return the length of the initial segment of S which
consists entirely of characters in ACCEPT. */
extern size_t EXFUN(strspn, (CONST char *__s, CONST char *__accept));
/* Find the first occurence in S of any character in ACCEPT. */
extern char *EXFUN(strpbrk, (CONST char *__s, CONST char *__accept));
/* Find the first occurence of NEEDLE in HAYSTACK. */
extern char *EXFUN(strstr, (CONST char *__haystack, CONST char *__needle));
/* Divide S into tokens separated by characters in DELIM. */
extern char *EXFUN(strtok, (char *__s, CONST char *__delim));
#ifdef __USE_GNU
/* Find the first occurence of NEEDLE in HAYSTACK.
NEEDLE is NEEDLE_LEN bytes long;
HAYSTACK is HAYSTACK_LEN bytes long. */
extern PTR EXFUN(memmem, (PTR __needle, size_t __needle_len,
PTR __haystack, size_t __haystack_len));
#endif
/* Return the length of S. */
extern size_t EXFUN(strlen, (CONST char *__s));
/* Return a string describing the meaning of the errno code in ERRNUM. */
extern char *EXFUN(strerror, (int __errnum));
#ifdef __USE_BSD
/* Compare S1 and S2, ignoring case. */
extern int EXFUN(strcasecmp, (CONST char *__s1, CONST char *__s2));
#endif
#ifdef __USE_GNU
/* Return a string describing the meaning of the signal number in SIG. */
extern char *EXFUN(strsignal, (int __sig));
/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */
extern char *EXFUN(stpcpy, (char *__dest, CONST char *__src));
#endif
#endif /* string.h */

View File

@@ -0,0 +1,39 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
/* Compatibility with BSD string(3). */
#ifndef _STRINGS_H
#define _STRINGS_H 1
#include <features.h>
#ifndef _STRING_H
#include <string.h>
#endif /* string.h */
/* These do not depend on __USE_BSD because
<strings.h> is a BSD-only header. */
/* Find the first occurrence of C in S. */
extern char *EXFUN(index, (CONST char *__s, int __c));
/* Find the last occurrence of C in S. */
extern char *EXFUN(rindex, (CONST char *__s, int __c));
#endif /* strings.h */

View File

@@ -0,0 +1,49 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <signal.h>
#include <stdio.h>
#include <string.h>
#ifndef HAVE_GNU_LD
#define _sys_siglist sys_siglist
#endif
/* Defined in , 1992siglist.c. */
extern CONST char *CONST _sys_siglist[];
/* Return a string describing the meaning of the signal number SIGNUM. */
char *
DEFUN(strsignal, (signum), int signum)
{
if (signum < 0 || signum > NSIG)
{
static char unknown_signal[] = "Unknown signal 000000000000000000";
static char fmt[] = "Unknown signal%d";
size_t len = sprintf(unknown_signal, fmt, signum);
if (len < sizeof(fmt) - 2)
return NULL;
unknown_signal[len - 1] = '\0';
return unknown_signal;
}
return (char *) _sys_siglist[signum];
}

View File

@@ -0,0 +1,73 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <errno.h>
#include <string.h>
static char *olds = NULL;
/* Parse S into tokens separated by characters in DELIM.
If S is NULL, the last string strtok() was called with is
used. For example:
char s[] = "-abc=-def";
x = strtok(s, "-"); // x = "abc"
x = strtok(NULL, "=-"); // x = "def"
x = strtok(NULL, "="); // x = NULL
// s = "abc\0-def\0"
*/
char *
DEFUN(strtok, (s, delim),
register char *s AND register CONST char *delim)
{
char *token;
if (s == NULL)
{
if (olds == NULL)
{
errno = EINVAL;
return NULL;
}
else
s = olds;
}
/* Scan leading delimiters. */
s += strspn(s, delim);
if (*s == '\0')
{
olds = NULL;
return NULL;
}
/* Find the end of the token. */
token = s;
s = strpbrk(token, delim);
if (s == NULL)
/* This token finishes the string. */
olds = NULL;
else
{
/* Terminate the token and make OLDS point past it. */
*s = '\0';
olds = s + 1;
}
return token;
}

View File

@@ -0,0 +1,76 @@
/* Copyright (C) 1991 Free Software Foundation, Inc.
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <localeinfo.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
/* Transform SRC into a form such that the result of strcmp
on two strings that have been transformed by strxfrm is
the same as the result of strcoll on the two strings before
their transformation. The transformed string is put in at
most N characters of DEST and its length is returned. */
size_t
DEFUN(strxfrm, (dest, src, n), char *dest AND CONST char *src AND size_t n)
{
CONST unsigned char *CONST values
= _collate_info != NULL ? _collate_info->values : NULL;
CONST unsigned char *CONST offsets
= _collate_info != NULL ? _collate_info->offsets : NULL;
register size_t done = 0;
while (*src != '\0')
{
CONST unsigned char c = *src++;
++done;
if (offsets != NULL && offsets[c] != 0)
{
++done;
if (offsets[c] == CHAR_MAX)
++done;
}
if (done < n && dest != NULL)
{
if (values == NULL)
*dest++ = c;
else if (values[c] == UCHAR_MAX && offsets[c] == 0)
/* This is a non-collating element. Skip it. */
;
else if (values[c] == UCHAR_MAX && offsets[c] == CHAR_MAX)
{
/* This element collates lower than anything else. */
*dest++ = '\001';
*dest++ = '\001';
*dest++ = '\001';
}
else
{
*dest++ = values[c];
*dest++ = offsets[c];
}
}
}
if (dest != NULL)
*dest = '\0';
return done;
}

View File

@@ -0,0 +1,111 @@
/* Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc.
Contributed by Torbjorn Granlund (tege@sics.se).
This file is part of the GNU C Library.
The GNU C Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The GNU C Library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the GNU C Library; see the file COPYING.LIB. If
not, write to the Free Software Foundation, Inc., 675 Mass Ave,
Cambridge, MA 02139, USA. */
#include <ansidecl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <malloc.h>
int
DEFUN(main, (argc, argv),
int argc AND char **argv)
{
char *mem, *memp;
char *rand_mem;
char *lo_around, *hi_around;
int size, max_size;
int src_off, dst_off;
int i;
int space_around = 10;
max_size = 256;
mem = malloc (max_size + 2 * max_size + 2 * space_around);
rand_mem = malloc (max_size);
lo_around = malloc (space_around);
hi_around = malloc (space_around);
memp = mem + space_around;
/* Fill RAND_MEM with random bytes, each non-zero. */
for (i = 0; i < max_size; i++)
{
int x;
do
x = random ();
while (x == 0);
rand_mem[i] = x;
}
for (size = 0; size < max_size; size++)
{
printf("phase %d\n", size);
for (src_off = 0; src_off <= 16; src_off++)
{
for (dst_off = 0; dst_off <= 16; dst_off++)
{
/* Put zero around the intended destination, to check
that it's not clobbered. */
for (i = 1; i < space_around; i++)
{
memp[dst_off - i] = 0;
memp[dst_off + size - 1 + i] = 0;
}
/* Fill the source area with known contents. */
for (i = 0; i < size; i++)
memp[src_off + i] = rand_mem[i];
/* Remember the contents around the destination area.
(It might not be what we wrote some lines above, since
the src area and the dst area overlap.) */
for (i = 1; i < space_around; i++)
{
lo_around[i] = memp[dst_off - i];
hi_around[i] = memp[dst_off + size - 1 + i];
}
memmove (memp + dst_off, memp + src_off, size);
/* Check that the destination area has the same
contents we wrote to the source area. */
for (i = 0; i < size; i++)
{
if (memp[dst_off + i] != rand_mem[i])
abort ();
}
/* Check that the area around the destination is not
clobbered. */
for (i = 1; i < space_around; i++)
{
if (memp[dst_off - i] != lo_around[i])
abort ();
if (memp[dst_off + size - 1 + i] != hi_around[i])
abort ();
}
}
}
}
puts ("Test succeeded.");
return 0;
}

View File

@@ -0,0 +1,551 @@
#include <ansidecl.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <bstring.h>
#include <fcntl.h>
#define STREQ(a, b) (strcmp((a), (b)) == 0)
CONST char *it = "<UNSET>"; /* Routine name for message routines. */
size_t errors = 0;
/* Complain if condition is not true. */
void
DEFUN(check, (thing, number), int thing AND int number)
{
if (!thing)
{
printf("%s flunked test %d\n", it, number);
++errors;
}
}
/* Complain if first two args don't strcmp as equal. */
void
DEFUN(equal, (a, b, number), CONST char *a AND CONST char *b AND int number)
{
check(a != NULL && b != NULL && STREQ(a, b), number);
}
char one[50];
char two[50];
int
DEFUN(main, (argc, argv), int argc AND char **argv)
{
/* Test strcmp first because we use it to test other things. */
it = "strcmp";
check(strcmp("", "") == 0, 1); /* Trivial case. */
check(strcmp("a", "a") == 0, 2); /* Identity. */
check(strcmp("abc", "abc") == 0, 3); /* Multicharacter. */
check(strcmp("abc", "abcd") < 0, 4); /* Length mismatches. */
check(strcmp("abcd", "abc") > 0, 5);
check(strcmp("abcd", "abce") < 0, 6); /* Honest miscompares. */
check(strcmp("abce", "abcd") > 0, 7);
check(strcmp("a\203", "a") > 0, 8); /* Tricky if char signed. */
check(strcmp("a\203", "a\003") > 0, 9);
/* Test strcpy next because we need it to set up other tests. */
it = "strcpy";
check(strcpy(one, "abcd") == one, 1); /* Returned value. */
equal(one, "abcd", 2); /* Basic test. */
(void) strcpy(one, "x");
equal(one, "x", 3); /* Writeover. */
equal(one+2, "cd", 4); /* Wrote too much? */
(void) strcpy(two, "hi there");
(void) strcpy(one, two);
equal(one, "hi there", 5); /* Basic test encore. */
equal(two, "hi there", 6); /* Stomped on source? */
(void) strcpy(one, "");
equal(one, "", 7); /* Boundary condition. */
/* strcat. */
it = "strcat";
(void) strcpy(one, "ijk");
check(strcat(one, "lmn") == one, 1); /* Returned value. */
equal(one, "ijklmn", 2); /* Basic test. */
(void) strcpy(one, "x");
(void) strcat(one, "yz");
equal(one, "xyz", 3); /* Writeover. */
equal(one+4, "mn", 4); /* Wrote too much? */
(void) strcpy(one, "gh");
(void) strcpy(two, "ef");
(void) strcat(one, two);
equal(one, "ghef", 5); /* Basic test encore. */
equal(two, "ef", 6); /* Stomped on source? */
(void) strcpy(one, "");
(void) strcat(one, "");
equal(one, "", 7); /* Boundary conditions. */
(void) strcpy(one, "ab");
(void) strcat(one, "");
equal(one, "ab", 8);
(void) strcpy(one, "");
(void) strcat(one, "cd");
equal(one, "cd", 9);
/* strncat - first test it as strcat, with big counts,
then test the count mechanism. */
it = "strncat";
(void) strcpy(one, "ijk");
check(strncat(one, "lmn", 99) == one, 1); /* Returned value. */
equal(one, "ijklmn", 2); /* Basic test. */
(void) strcpy(one, "x");
(void) strncat(one, "yz", 99);
equal(one, "xyz", 3); /* Writeover. */
equal(one+4, "mn", 4); /* Wrote too much? */
(void) strcpy(one, "gh");
(void) strcpy(two, "ef");
(void) strncat(one, two, 99);
equal(one, "ghef", 5); /* Basic test encore. */
equal(two, "ef", 6); /* Stomped on source? */
(void) strcpy(one, "");
(void) strncat(one, "", 99);
equal(one, "", 7); /* Boundary conditions. */
(void) strcpy(one, "ab");
(void) strncat(one, "", 99);
equal(one, "ab", 8);
(void) strcpy(one, "");
(void) strncat(one, "cd", 99);
equal(one, "cd", 9);
(void) strcpy(one, "ab");
(void) strncat(one, "cdef", 2);
equal(one, "abcd", 10); /* Count-limited. */
(void) strncat(one, "gh", 0);
equal(one, "abcd", 11); /* Zero count. */
(void) strncat(one, "gh", 2);
equal(one, "abcdgh", 12); /* Count and length equal. */
/* strncmp - first test as strcmp with big counts,
then test count code. */
it = "strncmp";
check(strncmp("", "", 99) == 0, 1); /* Trivial case. */
check(strncmp("a", "a", 99) == 0, 2); /* Identity. */
check(strncmp("abc", "abc", 99) == 0, 3); /* Multicharacter. */
check(strncmp("abc", "abcd", 99) < 0, 4); /* Length unequal. */
check(strncmp("abcd", "abc", 99) > 0, 5);
check(strncmp("abcd", "abce", 99) < 0, 6); /* Honestly unequal. */
check(strncmp("abce", "abcd", 99) > 0, 7);
check(strncmp("a\203", "a", 2) > 0, 8); /* Tricky if '\203' < 0 */
check(strncmp("a\203", "a\003", 2) > 0, 9);
check(strncmp("abce", "abcd", 3) == 0, 10); /* Count limited. */
check(strncmp("abce", "abc", 3) == 0, 11); /* Count == length. */
check(strncmp("abcd", "abce", 4) < 0, 12); /* Nudging limit. */
check(strncmp("abc", "def", 0) == 0, 13); /* Zero count. */
/* strncpy - testing is a bit different because of odd semantics. */
it = "strncpy";
check(strncpy(one, "abc", 4) == one, 1); /* Returned value. */
equal(one, "abc", 2); /* Did the copy go right? */
(void) strcpy(one, "abcdefgh");
(void) strncpy(one, "xyz", 2);
equal(one, "xycdefgh", 3); /* Copy cut by count. */
(void) strcpy(one, "abcdefgh");
(void) strncpy(one, "xyz", 3); /* Copy cut just before NUL. */
equal(one, "xyzdefgh", 4);
(void) strcpy(one, "abcdefgh");
(void) strncpy(one, "xyz", 4); /* Copy just includes NUL. */
equal(one, "xyz", 5);
equal(one+4, "efgh", 6); /* Wrote too much? */
(void) strcpy(one, "abcdefgh");
(void) strncpy(one, "xyz", 5); /* Copy includes padding. */
equal(one, "xyz", 7);
equal(one+4, "", 8);
equal(one+5, "fgh", 9);
(void) strcpy(one, "abc");
(void) strncpy(one, "xyz", 0); /* Zero-length copy. */
equal(one, "abc", 10);
(void) strncpy(one, "", 2); /* Zero-length source. */
equal(one, "", 11);
equal(one+1, "", 12);
equal(one+2, "c", 13);
(void) strcpy(one, "hi there");
(void) strncpy(two, one, 9);
equal(two, "hi there", 14); /* Just paranoia. */
equal(one, "hi there", 15); /* Stomped on source? */
/* strlen. */
it = "strlen";
check(strlen("") == 0, 1); /* Empty. */
check(strlen("a") == 1, 2); /* Single char. */
check(strlen("abcd") == 4, 3); /* Multiple chars. */
/* strchr. */
it = "strchr";
check(strchr("abcd", 'z') == NULL, 1); /* Not found. */
(void) strcpy(one, "abcd");
check(strchr(one, 'c') == one+2, 2); /* Basic test. */
check(strchr(one, 'd') == one+3, 3); /* End of string. */
check(strchr(one, 'a') == one, 4); /* Beginning. */
check(strchr(one, '\0') == one+4, 5); /* Finding NUL. */
(void) strcpy(one, "ababa");
check(strchr(one, 'b') == one+1, 6); /* Finding first. */
(void) strcpy(one, "");
check(strchr(one, 'b') == NULL, 7); /* Empty string. */
check(strchr(one, '\0') == one, 8); /* NUL in empty string. */
/* index - just like strchr. */
it = "index";
check(index("abcd", 'z') == NULL, 1); /* Not found. */
(void) strcpy(one, "abcd");
check(index(one, 'c') == one+2, 2); /* Basic test. */
check(index(one, 'd') == one+3, 3); /* End of string. */
check(index(one, 'a') == one, 4); /* Beginning. */
check(index(one, '\0') == one+4, 5); /* Finding NUL. */
(void) strcpy(one, "ababa");
check(index(one, 'b') == one+1, 6); /* Finding first. */
(void) strcpy(one, "");
check(index(one, 'b') == NULL, 7); /* Empty string. */
check(index(one, '\0') == one, 8); /* NUL in empty string. */
/* strrchr. */
it = "strrchr";
check(strrchr("abcd", 'z') == NULL, 1); /* Not found. */
(void) strcpy(one, "abcd");
check(strrchr(one, 'c') == one+2, 2); /* Basic test. */
check(strrchr(one, 'd') == one+3, 3); /* End of string. */
check(strrchr(one, 'a') == one, 4); /* Beginning. */
check(strrchr(one, '\0') == one+4, 5); /* Finding NUL. */
(void) strcpy(one, "ababa");
check(strrchr(one, 'b') == one+3, 6); /* Finding last. */
(void) strcpy(one, "");
check(strrchr(one, 'b') == NULL, 7); /* Empty string. */
check(strrchr(one, '\0') == one, 8); /* NUL in empty string. */
/* rindex - just like strrchr. */
it = "rindex";
check(rindex("abcd", 'z') == NULL, 1); /* Not found. */
(void) strcpy(one, "abcd");
check(rindex(one, 'c') == one+2, 2); /* Basic test. */
check(rindex(one, 'd') == one+3, 3); /* End of string. */
check(rindex(one, 'a') == one, 4); /* Beginning. */
check(rindex(one, '\0') == one+4, 5); /* Finding NUL. */
(void) strcpy(one, "ababa");
check(rindex(one, 'b') == one+3, 6); /* Finding last. */
(void) strcpy(one, "");
check(rindex(one, 'b') == NULL, 7); /* Empty string. */
check(rindex(one, '\0') == one, 8); /* NUL in empty string. */
/* strpbrk - somewhat like strchr. */
it = "strpbrk";
check(strpbrk("abcd", "z") == NULL, 1); /* Not found. */
(void) strcpy(one, "abcd");
check(strpbrk(one, "c") == one+2, 2); /* Basic test. */
check(strpbrk(one, "d") == one+3, 3); /* End of string. */
check(strpbrk(one, "a") == one, 4); /* Beginning. */
check(strpbrk(one, "") == NULL, 5); /* Empty search list. */
check(strpbrk(one, "cb") == one+1, 6); /* Multiple search. */
(void) strcpy(one, "abcabdea");
check(strpbrk(one, "b") == one+1, 7); /* Finding first. */
check(strpbrk(one, "cb") == one+1, 8); /* With multiple search. */
check(strpbrk(one, "db") == one+1, 9); /* Another variant. */
(void) strcpy(one, "");
check(strpbrk(one, "bc") == NULL, 10); /* Empty string. */
check(strpbrk(one, "") == NULL, 11); /* Both strings empty. */
/* strstr - somewhat like strchr. */
it = "strstr";
check(strstr("abcd", "z") == NULL, 1); /* Not found. */
check(strstr("abcd", "abx") == NULL, 2); /* Dead end. */
(void) strcpy(one, "abcd");
check(strstr(one, "c") == one+2, 3); /* Basic test. */
check(strstr(one, "bc") == one+1, 4); /* Multichar. */
check(strstr(one, "d") == one+3, 5); /* End of string. */
check(strstr(one, "cd") == one+2, 6); /* Tail of string. */
check(strstr(one, "abc") == one, 7); /* Beginning. */
check(strstr(one, "abcd") == one, 8); /* Exact match. */
check(strstr(one, "abcde") == NULL, 9); /* Too long. */
check(strstr(one, "de") == NULL, 10); /* Past end. */
check(strstr(one, "") == one+4, 11); /* Finding empty. */
(void) strcpy(one, "ababa");
check(strstr(one, "ba") == one+1, 12); /* Finding first. */
(void) strcpy(one, "");
check(strstr(one, "b") == NULL, 13); /* Empty string. */
check(strstr(one, "") == one, 14); /* Empty in empty string. */
(void) strcpy(one, "bcbca");
check(strstr(one, "bca") == one+2, 15); /* False start. */
(void) strcpy(one, "bbbcabbca");
check(strstr(one, "bbca") == one+1, 16); /* With overlap. */
/* strspn. */
it = "strspn";
check(strspn("abcba", "abc") == 5, 1); /* Whole string. */
check(strspn("abcba", "ab") == 2, 2); /* Partial. */
check(strspn("abc", "qx") == 0, 3); /* None. */
check(strspn("", "ab") == 0, 4); /* Null string. */
check(strspn("abc", "") == 0, 5); /* Null search list. */
/* strcspn. */
it = "strcspn";
check(strcspn("abcba", "qx") == 5, 1); /* Whole string. */
check(strcspn("abcba", "cx") == 2, 2); /* Partial. */
check(strcspn("abc", "abc") == 0, 3); /* None. */
check(strcspn("", "ab") == 0, 4); /* Null string. */
check(strcspn("abc", "") == 3, 5); /* Null search list. */
/* strtok - the hard one. */
it = "strtok";
(void) strcpy(one, "first, second, third");
equal(strtok(one, ", "), "first", 1); /* Basic test. */
equal(one, "first", 2);
equal(strtok((char *)NULL, ", "), "second", 3);
equal(strtok((char *)NULL, ", "), "third", 4);
check(strtok((char *)NULL, ", ") == NULL, 5);
(void) strcpy(one, ", first, ");
equal(strtok(one, ", "), "first", 6); /* Extra delims, 1 tok. */
check(strtok((char *)NULL, ", ") == NULL, 7);
(void) strcpy(one, "1a, 1b; 2a, 2b");
equal(strtok(one, ", "), "1a", 8); /* Changing delim lists. */
equal(strtok((char *)NULL, "; "), "1b", 9);
equal(strtok((char *)NULL, ", "), "2a", 10);
(void) strcpy(two, "x-y");
equal(strtok(two, "-"), "x", 11); /* New string before done. */
equal(strtok((char *)NULL, "-"), "y", 12);
check(strtok((char *)NULL, "-") == NULL, 13);
(void) strcpy(one, "a,b, c,, ,d");
equal(strtok(one, ", "), "a", 14); /* Different separators. */
equal(strtok((char *)NULL, ", "), "b", 15);
equal(strtok((char *)NULL, " ,"), "c", 16); /* Permute list too. */
equal(strtok((char *)NULL, " ,"), "d", 17);
check(strtok((char *)NULL, ", ") == NULL, 18);
check(strtok((char *)NULL, ", ") == NULL, 19); /* Persistence. */
(void) strcpy(one, ", ");
check(strtok(one, ", ") == NULL, 20); /* No tokens. */
(void) strcpy(one, "");
check(strtok(one, ", ") == NULL, 21); /* Empty string. */
(void) strcpy(one, "abc");
equal(strtok(one, ", "), "abc", 22); /* No delimiters. */
check(strtok((char *)NULL, ", ") == NULL, 23);
(void) strcpy(one, "abc");
equal(strtok(one, ""), "abc", 24); /* Empty delimiter list. */
check(strtok((char *)NULL, "") == NULL, 25);
(void) strcpy(one, "abcdefgh");
(void) strcpy(one, "a,b,c");
equal(strtok(one, ","), "a", 26); /* Basics again... */
equal(strtok((char *)NULL, ","), "b", 27);
equal(strtok((char *)NULL, ","), "c", 28);
check(strtok((char *)NULL, ",") == NULL, 29);
equal(one+6, "gh", 30); /* Stomped past end? */
equal(one, "a", 31); /* Stomped old tokens? */
equal(one+2, "b", 32);
equal(one+4, "c", 33);
/* memcmp. */
it = "memcmp";
check(memcmp("a", "a", 1) == 0, 1); /* Identity. */
check(memcmp("abc", "abc", 3) == 0, 2); /* Multicharacter. */
check(memcmp("abcd", "abce", 4) < 0, 3); /* Honestly unequal. */
check(memcmp("abce", "abcd", 4) > 0, 4);
check(memcmp("alph", "beta", 4) < 0, 5);
check(memcmp("a\203", "a\003", 2) > 0, 6);
check(memcmp("abce", "abcd", 3) == 0, 7); /* Count limited. */
check(memcmp("abc", "def", 0) == 0, 8); /* Zero count. */
/* memchr. */
it = "memchr";
check(memchr("abcd", 'z', 4) == NULL, 1); /* Not found. */
(void) strcpy(one, "abcd");
check(memchr(one, 'c', 4) == one+2, 2); /* Basic test. */
check(memchr(one, 'd', 4) == one+3, 3); /* End of string. */
check(memchr(one, 'a', 4) == one, 4); /* Beginning. */
check(memchr(one, '\0', 5) == one+4, 5); /* Finding NUL. */
(void) strcpy(one, "ababa");
check(memchr(one, 'b', 5) == one+1, 6); /* Finding first. */
check(memchr(one, 'b', 0) == NULL, 7); /* Zero count. */
check(memchr(one, 'a', 1) == one, 8); /* Singleton case. */
(void) strcpy(one, "a\203b");
check(memchr(one, 0203, 3) == one+1, 9); /* Unsignedness. */
/* memcpy - need not work for overlap. */
it = "memcpy";
check(memcpy(one, "abc", 4) == one, 1); /* Returned value. */
equal(one, "abc", 2); /* Did the copy go right? */
(void) strcpy(one, "abcdefgh");
(void) memcpy(one+1, "xyz", 2);
equal(one, "axydefgh", 3); /* Basic test. */
(void) strcpy(one, "abc");
(void) memcpy(one, "xyz", 0);
equal(one, "abc", 4); /* Zero-length copy. */
(void) strcpy(one, "hi there");
(void) strcpy(two, "foo");
(void) memcpy(two, one, 9);
equal(two, "hi there", 5); /* Just paranoia. */
equal(one, "hi there", 6); /* Stomped on source? */
/* memmove - must work on overlap. */
it = "memmove";
check(memmove(one, "abc", 4) == one, 1); /* Returned value. */
equal(one, "abc", 2); /* Did the copy go right? */
(void) strcpy(one, "abcdefgh");
(void) memmove(one+1, "xyz", 2);
equal(one, "axydefgh", 3); /* Basic test. */
(void) strcpy(one, "abc");
(void) memmove(one, "xyz", 0);
equal(one, "abc", 4); /* Zero-length copy. */
(void) strcpy(one, "hi there");
(void) strcpy(two, "foo");
(void) memmove(two, one, 9);
equal(two, "hi there", 5); /* Just paranoia. */
equal(one, "hi there", 6); /* Stomped on source? */
(void) strcpy(one, "abcdefgh");
(void) memmove(one+1, one, 9);
equal(one, "aabcdefgh", 7); /* Overlap, right-to-left. */
(void) strcpy(one, "abcdefgh");
(void) memmove(one+1, one+2, 7);
equal(one, "acdefgh", 8); /* Overlap, left-to-right. */
(void) strcpy(one, "abcdefgh");
(void) memmove(one, one, 9);
equal(one, "abcdefgh", 9); /* 100% overlap. */
/* memccpy - first test like memcpy, then the search part
The SVID, the only place where memccpy is mentioned, says
overlap might fail, so we don't try it. Besides, it's hard
to see the rationale for a non-left-to-right memccpy. */
it = "memccpy";
check(memccpy(one, "abc", 'q', 4) == NULL, 1); /* Returned value. */
equal(one, "abc", 2); /* Did the copy go right? */
(void) strcpy(one, "abcdefgh");
(void) memccpy(one+1, "xyz", 'q', 2);
equal(one, "axydefgh", 3); /* Basic test. */
(void) strcpy(one, "abc");
(void) memccpy(one, "xyz", 'q', 0);
equal(one, "abc", 4); /* Zero-length copy. */
(void) strcpy(one, "hi there");
(void) strcpy(two, "foo");
(void) memccpy(two, one, 'q', 9);
equal(two, "hi there", 5); /* Just paranoia. */
equal(one, "hi there", 6); /* Stomped on source? */
(void) strcpy(one, "abcdefgh");
(void) strcpy(two, "horsefeathers");
check(memccpy(two, one, 'f', 9) == two+6, 7); /* Returned value. */
equal(one, "abcdefgh", 8); /* Source intact? */
equal(two, "abcdefeathers", 9); /* Copy correct? */
(void) strcpy(one, "abcd");
(void) strcpy(two, "bumblebee");
check(memccpy(two, one, 'a', 4) == two+1, 10); /* First char. */
equal(two, "aumblebee", 11);
check(memccpy(two, one, 'd', 4) == two+4, 12); /* Last char. */
equal(two, "abcdlebee", 13);
(void) strcpy(one, "xyz");
check(memccpy(two, one, 'x', 1) == two+1, 14); /* Singleton. */
equal(two, "xbcdlebee", 15);
/* memset. */
it = "memset";
(void) strcpy(one, "abcdefgh");
check(memset(one+1, 'x', 3) == one+1, 1); /* Return value. */
equal(one, "axxxefgh", 2); /* Basic test. */
(void) memset(one+2, 'y', 0);
equal(one, "axxxefgh", 3); /* Zero-length set. */
(void) memset(one+5, 0, 1);
equal(one, "axxxe", 4); /* Zero fill. */
equal(one+6, "gh", 5); /* And the leftover. */
(void) memset(one+2, 010045, 1);
equal(one, "ax\045xe", 6); /* Unsigned char convert. */
/* bcopy - much like memcpy.
Berklix manual is silent about overlap, so don't test it. */
it = "bcopy";
(void) bcopy("abc", one, 4);
equal(one, "abc", 1); /* Simple copy. */
(void) strcpy(one, "abcdefgh");
(void) bcopy("xyz", one+1, 2);
equal(one, "axydefgh", 2); /* Basic test. */
(void) strcpy(one, "abc");
(void) bcopy("xyz", one, 0);
equal(one, "abc", 3); /* Zero-length copy. */
(void) strcpy(one, "hi there");
(void) strcpy(two, "foo");
(void) bcopy(one, two, 9);
equal(two, "hi there", 4); /* Just paranoia. */
equal(one, "hi there", 5); /* Stomped on source? */
/* bzero. */
it = "bzero";
(void) strcpy(one, "abcdef");
bzero(one+2, 2);
equal(one, "ab", 1); /* Basic test. */
equal(one+3, "", 2);
equal(one+4, "ef", 3);
(void) strcpy(one, "abcdef");
bzero(one+2, 0);
equal(one, "abcdef", 4); /* Zero-length copy. */
/* bcmp - somewhat like memcmp. */
it = "bcmp";
check(bcmp("a", "a", 1) == 0, 1); /* Identity. */
check(bcmp("abc", "abc", 3) == 0, 2); /* Multicharacter. */
check(bcmp("abcd", "abce", 4) != 0, 3); /* Honestly unequal. */
check(bcmp("abce", "abcd", 4) != 0, 4);
check(bcmp("alph", "beta", 4) != 0, 5);
check(bcmp("abce", "abcd", 3) == 0, 6); /* Count limited. */
check(bcmp("abc", "def", 0) == 0, 8); /* Zero count. */
/* strerror - VERY system-dependent. */
{
extern CONST unsigned int _sys_nerr;
extern CONST char *CONST _sys_errlist[];
int f;
it = "strerror";
f = open("/", O_WRONLY); /* Should always fail. */
check(f < 0 && errno > 0 && errno < _sys_nerr, 1);
equal(strerror(errno), _sys_errlist[errno], 2);
}
{
int status;
if (errors == 0)
{
status = EXIT_SUCCESS;
puts("No errors.");
}
else
{
status = EXIT_FAILURE;
printf("%Z errors.\n", errors);
}
exit(status);
}
}