Remove functions that also exist in libc.

Some of these functions were slightly different from libc:

 - This strncpy() didn't pad the buffer with '\0' bytes beyond the end
   of the string; libc does the padding.  This string.3 manual said
   that this strncpy() does "null-padding", but it didn't.

 - This strcmp() and strncmp() compared using char (which might be
   signed); libc compares using unsigned char.
This commit is contained in:
George Koehler 2017-11-09 23:25:17 -05:00
parent ca4bd38206
commit 6367467499
10 changed files with 19 additions and 255 deletions

View file

@ -7,25 +7,16 @@
#ifndef __ACK_STRING_INCLUDED__
#define __ACK_STRING_INCLUDED__
#include <ansi.h>
_PROTOTYPE(char *strcpy, (char *s1, const char *s2));
_PROTOTYPE(char *strncpy, (char *s1, const char *s2, size_t n));
_PROTOTYPE(char *strcat, (char *s1, const char *s2));
_PROTOTYPE(char *strncat, (char *s1, const char *s2, size_t n));
_PROTOTYPE(int strcmp, (const char *s1, const char *s2));
_PROTOTYPE(int strncmp, (const char *s1, const char *s2, size_t n));
_PROTOTYPE(_SIZET strlen, (const char *s));
_PROTOTYPE(char *strindex, (char *s, int c));
_PROTOTYPE(char *strrindex, (char *s, int c));
_PROTOTYPE(char *strzero, (char *s));
_PROTOTYPE(char *str2bts, (char *s, char *b, int *n));
_PROTOTYPE(char *long2str, (long l, int b));
_PROTOTYPE(long str2long, (char *s, int b));
_PROTOTYPE(char *btscpy, (char *s1, char *s2, int n));
_PROTOTYPE(char *btscat, (char *s1, int n1, char *s2, int n2));
_PROTOTYPE(int btscmp, (char *s1, int n1, char *s2, int n2));
_PROTOTYPE(char *btszero, (char *b, int n));
_PROTOTYPE(char *bts2str, (char *b, int n, char *s));
char *strindex(char *s, int c);
char *strrindex(char *s, int c);
char *strzero(char *s);
char *str2bts(char *s, char *b, int *n);
char *long2str(long l, int b);
long str2long(char *s, int b);
char *btscpy(char *s1, char *s2, int n);
char *btscat(char *s1, int n1, char *s2, int n2);
int btscmp(char *s1, int n1, char *s2, int n2);
char *btszero(char *b, int n);
char *bts2str(char *b, int n, char *s);
#endif /* __ACK_STRING_INCLUDED__ */

View file

@ -1,10 +1,13 @@
clibrary {
name = "lib",
srcs = { "./*.c" },
srcs = {
"./bts2str.c", "./btscat.c", "./btscmp.c",
"./btscpy.c", "./btszero.c", "./long2str.c",
"./str2bts.c", "./str2long.c", "./strindex.c",
"./strrindex.c", "./strzero.c",
},
deps = {
"./ack_string.h",
"modules+headers",
"./*.h"
},
}

View file

@ -1,24 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* append t to s
*/
#include "ack_string.h"
char *
strcat(s, t)
register char *s;
register _CONST char *t;
{
register char *b = s;
while (*s++)
;
s--;
while (*s++ = *t++)
;
return b;
}

View file

@ -1,20 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* return negative, zero or positive value if
resp. s < t, s == t or s > t
*/
#include "ack_string.h"
int
strcmp(s, t)
register _CONST char *s, *t;
{
while (*s == *t++)
if (*s++ == '\0')
return 0;
return *s - *--t;
}

View file

@ -1,21 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* Copy t into s
*/
#include "ack_string.h"
char *
strcpy(s, t)
register char *s;
register _CONST char *t;
{
register char *b = s;
while (*s++ = *t++)
;
return b;
}

View file

@ -1,8 +1,7 @@
.TH STRING 3 "$Revision$"
.ad
.SH NAME
strcpy, strncpy, strcat, strncat, strcmp, strncmp,
strlen, strindex, strrindex, strzero, str2bts,
strindex, strrindex, strzero, str2bts,
long2str, str2long,
btscpy, btscat, btscmp, btszero, bts2str \- operations on and
conversions between strings and row of bytes
@ -10,27 +9,6 @@ conversions between strings and row of bytes
.nf
.B #include <ack_string.h>
.PP
.B char *strcpy(s1, s2)
.B char *s1, *s2;
.PP
.B char *strncpy(s1, s2, n)
.B char *s1, *s2;
.PP
.B char *strcat(s1, s2)
.B char *s1, *s2;
.PP
.B char *strncat(s1, s2, n)
.B char *s1, *s2;
.PP
.B int strcmp(s1, s2)
.B char *s1, *s2;
.PP
.B int strncmp(s1, s2, n)
.B char *s1, *s2;
.PP
.B int strlen(s)
.B char *s;
.PP
.B char *strindex(s, c)
.B char *s, c;
.PP
@ -82,56 +60,6 @@ functions operate on variable-length rows of bytes,
regardless of null bytes.
Neither of these functions check for overflow of any receiving area.
.PP
.I Strcpy
copies string
.I s2
to
.I s1,
stopping after the null character has been moved.
.I Strncpy
copies exactly
.I n
characters,
truncating or null-padding
.I s2;
the target may not be null-terminated if the length
of
.I s2
is
.I n
or more.
Both return
.IR s1 .
.PP
.I Strcat
appends a copy of string
.I s2
to the end of string
.IR s1 .
.I Strncat
copies at most
.I n
characters.
Both return a pointer to the null-terminated result
.IR s1 .
.PP
.I Strcmp
compares its arguments and returns an integer
greater than, equal to, or less than 0, if
.I s1
is lexicographically greater than, equal to, or
less than
.IR s2 ,
respectively.
.I Strncmp
makes the same comparison but checks at most
.I n
characters.
.PP
.I Strlen
returns the number of characters before the null-character.
.IR s .
.PP
.I Strindex
.RI ( strrindex )
returns a pointer to the first (last)

View file

@ -1,20 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* return length of s
*/
#include "ack_string.h"
_SIZET
strlen(s)
_CONST char *s;
{
register _CONST char *b = s;
while (*b++)
;
return b - s - 1;
}

View file

@ -1,25 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* append t to s, upto n characters
*/
#include "ack_string.h"
char *
strncat(s, t, n)
register char *s;
register _CONST char *t;
register _SIZET n;
{
register char *b = s;
while (*s++)
;
s--;
while ((n-- > 0) && (*s++ = *t++))
;
return b;
}

View file

@ -1,26 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* return negative, zero or positive value if
resp. s < t, s == t or s > t; compare at most n characters
*/
#include "ack_string.h"
int
strncmp(s, t, n)
register _CONST char *s, *t;
register _SIZET n;
{
while (n-- > 0) {
if (*s == *t++) {
if (*s++ == '\0')
return 0;
}
else
return *s - *--t;
}
return 0;
}

View file

@ -1,22 +0,0 @@
/* $Id$ */
/*
* (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
* See the copyright notice in the ACK home directory, in the file "Copyright".
*/
/* Copy t into s, upto n characters
*/
#include "ack_string.h"
char *
strncpy(s, t, n)
register char *s;
register _CONST char *t;
register _SIZET n;
{
register char *b = s;
while ((n-- > 0) && (*s++ = *t++))
;
return b;
}