diff options
Diffstat (limited to 'string')
| -rw-r--r-- | string/.cvsignore | 4 | ||||
| -rw-r--r-- | string/Makefile | 39 | ||||
| -rw-r--r-- | string/endian.h | 43 | ||||
| -rw-r--r-- | string/memfrob.c | 32 | ||||
| -rw-r--r-- | string/memory.h | 34 | ||||
| -rw-r--r-- | string/strcoll.c | 70 | ||||
| -rw-r--r-- | string/strdup.c | 38 | ||||
| -rw-r--r-- | string/strerror.c | 33 | ||||
| -rw-r--r-- | string/strfry.c | 46 | ||||
| -rw-r--r-- | string/string.h | 186 | ||||
| -rw-r--r-- | string/strings.h | 32 | ||||
| -rw-r--r-- | string/strsignal.c | 49 | ||||
| -rw-r--r-- | string/strtok.c | 73 | ||||
| -rw-r--r-- | string/strxfrm.c | 76 | ||||
| -rw-r--r-- | string/swab.c | 32 | ||||
| -rw-r--r-- | string/test-ffs.c | 54 | ||||
| -rw-r--r-- | string/testcopy.c | 111 | ||||
| -rw-r--r-- | string/tester.c | 570 |
18 files changed, 1522 insertions, 0 deletions
diff --git a/string/.cvsignore b/string/.cvsignore new file mode 100644 index 0000000000..1f69fd919a --- /dev/null +++ b/string/.cvsignore @@ -0,0 +1,4 @@ +*.gz *.Z *.tar *.tgz +=* +TODO COPYING* AUTHORS copyr-* copying.* +glibc-* diff --git a/string/Makefile b/string/Makefile new file mode 100644 index 0000000000..a4ba83b465 --- /dev/null +++ b/string/Makefile @@ -0,0 +1,39 @@ +# Copyright (C) 1991, 1992, 1993, 1994, 1995 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 memory.h endian.h bytesex.h + +routines := strcat strchr strcmp strcoll strcpy strcspn strdup \ + strerror _strerror strlen strncat strncmp strncpy \ + strrchr strpbrk strsignal strspn strstr strtok \ + strxfrm memchr memcmp memmove memset \ + bcopy bzero ffs stpcpy stpncpy \ + strcasecmp strncase \ + memccpy memcpy wordcopy strsep \ + swab strfry memfrob memmem + +tests := tester testcopy test-ffs +distribute := memcopy.h + + +include ../Rules diff --git a/string/endian.h b/string/endian.h new file mode 100644 index 0000000000..8871ff54d4 --- /dev/null +++ b/string/endian.h @@ -0,0 +1,43 @@ +/* Copyright (C) 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. */ + +#ifndef _ENDIAN_H +#define _ENDIAN_H 1 +#include <features.h> + +/* Definitions for byte order, according to significance of bytes, from low + addresses to high addresses. The value is what you get by putting '4' + in the most significant byte, '3' in the second most significant byte, + '2' in the second least significant byte, and '1' in the least + significant byte. */ + +#define __LITTLE_ENDIAN 1234 +#define __BIG_ENDIAN 4321 +#define __PDP_ENDIAN 3412 + +/* This file defines `__BYTE_ORDER' for the particular machine. */ +#include <bytesex.h> + +#ifdef __USE_BSD +#define LITTLE_ENDIAN __LITTLE_ENDIAN +#define BIG_ENDIAN __BIG_ENDIAN +#define PDP_ENDIAN __PDP_ENDIAN +#define BYTE_ORDER __BYTE_ORDER +#endif + +#endif /* endian.h */ diff --git a/string/memfrob.c b/string/memfrob.c new file mode 100644 index 0000000000..cf3422bdc7 --- /dev/null +++ b/string/memfrob.c @@ -0,0 +1,32 @@ +/* Copyright (C) 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> + +PTR +DEFUN(memfrob, (s, n), + PTR s AND size_t n) +{ + register char *p = (char *) s; + + while (n-- > 0) + *p++ ^= 42; + + return s; +} diff --git a/string/memory.h b/string/memory.h new file mode 100644 index 0000000000..901a291ea3 --- /dev/null +++ b/string/memory.h @@ -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 */ diff --git a/string/strcoll.c b/string/strcoll.c new file mode 100644 index 0000000000..ed4b35f80d --- /dev/null +++ b/string/strcoll.c @@ -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; + } +} diff --git a/string/strdup.c b/string/strdup.c new file mode 100644 index 0000000000..2c8aff2796 --- /dev/null +++ b/string/strdup.c @@ -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; +} diff --git a/string/strerror.c b/string/strerror.c new file mode 100644 index 0000000000..67759703c4 --- /dev/null +++ b/string/strerror.c @@ -0,0 +1,33 @@ +/* Copyright (C) 1991, 1993, 1994 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> + +extern char *_strerror_internal __P ((int, char buf[1024])); + +/* 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) +{ + static char buf[1024]; + return _strerror_internal (errnum, buf); +} diff --git a/string/strfry.c b/string/strfry.c new file mode 100644 index 0000000000..c885f66c68 --- /dev/null +++ b/string/strfry.c @@ -0,0 +1,46 @@ +/* Copyright (C) 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 <stdlib.h> +#include <time.h> + +char * +DEFUN(strfry, (string), char *string) +{ + static int init = 0; + size_t len, i; + + if (!init) + { + srand (time ((time_t *) NULL)); + init = 1; + } + + len = strlen (string); + for (i = 0; i < len; ++i) + { + size_t j = rand () % len; + char c = string[i]; + string[i] = string[j]; + string[j] = c; + } + + return string; +} diff --git a/string/string.h b/string/string.h new file mode 100644 index 0000000000..905d727f18 --- /dev/null +++ b/string/string.h @@ -0,0 +1,186 @@ +/* Copyright (C) 1991, 1992, 1993 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, 1992 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> + +__BEGIN_DECLS + +/* 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_t memcpy __P ((__ptr_t __dest, __const __ptr_t __src, + size_t __n)); +/* Copy N bytes of SRC to DEST, guaranteeing + correct behavior for overlapping strings. */ +extern __ptr_t memmove __P ((__ptr_t __dest, __const __ptr_t __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_t __memccpy __P ((__ptr_t __dest, __const __ptr_t __src, + int __c, size_t __n)); +#if defined (__USE_SVID) || defined (__USE_BSD) +extern __ptr_t memccpy __P ((__ptr_t __dest, __const __ptr_t __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_t memset __P ((__ptr_t __s, int __c, size_t __n)); + +/* Compare N bytes of S1 and S2. */ +extern int memcmp __P ((__const __ptr_t __s1, __const __ptr_t __s2, + size_t __n)); + +/* Search N bytes of S for C. */ +extern __ptr_t memchr __P ((__const __ptr_t __s, int __c, size_t __n)); + + +/* Copy SRC to DEST. */ +extern char *strcpy __P ((char *__dest, __const char *__src)); +/* Copy no more than N characters of SRC to DEST. */ +extern char *strncpy __P ((char *__dest, __const char *__src, size_t __n)); + +/* Append SRC onto DEST. */ +extern char *strcat __P ((char *__dest, __const char *__src)); +/* Append no more than N characters from SRC onto DEST. */ +extern char *strncat __P ((char *__dest, __const char *__src, size_t __n)); + +/* Compare S1 and S2. */ +extern int strcmp __P ((__const char *__s1, __const char *__s2)); +/* Compare N characters of S1 and S2. */ +extern int strncmp __P ((__const char *__s1, __const char *__s2, size_t __n)); + +/* Compare the collated forms of S1 and S2. */ +extern int strcoll __P ((__const char *__s1, __const char *__s2)); +/* Put a transformation of SRC into no more than N bytes of DEST. */ +extern size_t strxfrm __P ((char *__dest, __const char *__src, size_t __n)); + +#if defined (__USE_SVID) || defined (__USE_BSD) +/* Duplicate S, returning an identical malloc'd string. */ +extern char *strdup __P ((__const char *__s)); +#endif + +/* Find the first occurrence of C in S. */ +extern char *strchr __P ((__const char *__s, int __c)); +/* Find the last occurrence of C in S. */ +extern char *strrchr __P ((__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 strcspn __P ((__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 strspn __P ((__const char *__s, __const char *__accept)); +/* Find the first occurence in S of any character in ACCEPT. */ +extern char *strpbrk __P ((__const char *__s, __const char *__accept)); +/* Find the first occurence of NEEDLE in HAYSTACK. */ +extern char *strstr __P ((__const char *__haystack, __const char *__needle)); +/* Divide S into tokens separated by characters in DELIM. */ +extern char *strtok __P ((char *__s, __const char *__delim)); + +#ifdef __USE_GNU +/* Find the first occurence of NEEDLE in HAYSTACK. + NEEDLE is NEEDLELEN bytes long; + HAYSTACK is HAYSTACKLEN bytes long. */ +extern __ptr_t memmem __P ((__const __ptr_t __haystack, size_t __haystacklen, + __const __ptr_t __needle, size_t __needlelen)); +#endif + +/* Return the length of S. */ +extern size_t strlen __P ((__const char *__s)); + +/* Return a string describing the meaning of the errno code in ERRNUM. */ +extern char *strerror __P ((int __errnum)); + +#ifdef __USE_BSD +/* Find the first occurrence of C in S (same as strchr). */ +extern char *index __P ((__const char *__s, int __c)); + +/* Find the last occurrence of C in S (same as strrchr). */ +extern char *rindex __P ((__const char *__s, int __c)); + +/* Copy N bytes of SRC to DEST (like memmove, but args reversed). */ +extern void bcopy __P ((__const __ptr_t __src, __ptr_t __dest, size_t __n)); + +/* Set N bytes of S to 0. */ +extern void bzero __P ((__ptr_t __s, size_t __n)); + +/* Compare N bytes of S1 and S2 (same as memcmp). */ +extern int bcmp __P ((__const __ptr_t __s1, __const __ptr_t __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 ffs __P ((int __i)); + +/* Compare S1 and S2, ignoring case. */ +extern int strcasecmp __P ((__const char *__s1, __const char *__s2)); + +/* Return the next DELIM-delimited token from *STRINGP, + terminating it with a '\0', and update *STRINGP to point past it. */ +extern char *strsep __P ((char **__stringp, __const char *__delim)); +#endif + +/* Copy no more than N characters of SRC to DEST, returning the address of + the last character written into DEST. */ +extern char *__stpncpy __P ((char *__dest, __const char *__src, size_t __n)); + +#ifdef __USE_GNU +/* Compare no more than N chars of S1 and S2, ignoring case. */ +extern int strncasecmp __P ((__const char *__s1, __const char *__s2, + size_t __n)); + +/* Return a string describing the meaning of the signal number in SIG. */ +extern char *strsignal __P ((int __sig)); + +/* Copy SRC to DEST, returning the address of the terminating '\0' in DEST. */ +extern char *stpcpy __P ((char *__dest, __const char *__src)); + +/* Copy no more than N characters of SRC to DEST, returning the address of + the last character written into DEST. */ +extern char *stpncpy __P ((char *__dest, __const char *__src, size_t __n)); + +#ifdef __OPTIMIZE__ +#define stpncpy(dest, src, n) __stpncpy ((dest), (src), (n)) +#endif + +/* Sautee STRING briskly. */ +extern char *strfry __P ((char *__string)); + +/* Frobnicate N bytes of S. */ +extern __ptr_t memfrob __P ((__ptr_t __s, size_t __n)); +#endif + +__END_DECLS + +#endif /* string.h */ diff --git a/string/strings.h b/string/strings.h new file mode 100644 index 0000000000..235c3e5c9e --- /dev/null +++ b/string/strings.h @@ -0,0 +1,32 @@ +/* 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 |
