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:
parent
ca4bd38206
commit
6367467499
|
@ -7,25 +7,16 @@
|
||||||
#ifndef __ACK_STRING_INCLUDED__
|
#ifndef __ACK_STRING_INCLUDED__
|
||||||
#define __ACK_STRING_INCLUDED__
|
#define __ACK_STRING_INCLUDED__
|
||||||
|
|
||||||
#include <ansi.h>
|
char *strindex(char *s, int c);
|
||||||
|
char *strrindex(char *s, int c);
|
||||||
_PROTOTYPE(char *strcpy, (char *s1, const char *s2));
|
char *strzero(char *s);
|
||||||
_PROTOTYPE(char *strncpy, (char *s1, const char *s2, size_t n));
|
char *str2bts(char *s, char *b, int *n);
|
||||||
_PROTOTYPE(char *strcat, (char *s1, const char *s2));
|
char *long2str(long l, int b);
|
||||||
_PROTOTYPE(char *strncat, (char *s1, const char *s2, size_t n));
|
long str2long(char *s, int b);
|
||||||
_PROTOTYPE(int strcmp, (const char *s1, const char *s2));
|
char *btscpy(char *s1, char *s2, int n);
|
||||||
_PROTOTYPE(int strncmp, (const char *s1, const char *s2, size_t n));
|
char *btscat(char *s1, int n1, char *s2, int n2);
|
||||||
_PROTOTYPE(_SIZET strlen, (const char *s));
|
int btscmp(char *s1, int n1, char *s2, int n2);
|
||||||
_PROTOTYPE(char *strindex, (char *s, int c));
|
char *btszero(char *b, int n);
|
||||||
_PROTOTYPE(char *strrindex, (char *s, int c));
|
char *bts2str(char *b, int n, char *s);
|
||||||
_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));
|
|
||||||
|
|
||||||
#endif /* __ACK_STRING_INCLUDED__ */
|
#endif /* __ACK_STRING_INCLUDED__ */
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
clibrary {
|
clibrary {
|
||||||
name = "lib",
|
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 = {
|
deps = {
|
||||||
|
"./ack_string.h",
|
||||||
"modules+headers",
|
"modules+headers",
|
||||||
"./*.h"
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -1,8 +1,7 @@
|
||||||
.TH STRING 3 "$Revision$"
|
.TH STRING 3 "$Revision$"
|
||||||
.ad
|
.ad
|
||||||
.SH NAME
|
.SH NAME
|
||||||
strcpy, strncpy, strcat, strncat, strcmp, strncmp,
|
strindex, strrindex, strzero, str2bts,
|
||||||
strlen, strindex, strrindex, strzero, str2bts,
|
|
||||||
long2str, str2long,
|
long2str, str2long,
|
||||||
btscpy, btscat, btscmp, btszero, bts2str \- operations on and
|
btscpy, btscat, btscmp, btszero, bts2str \- operations on and
|
||||||
conversions between strings and row of bytes
|
conversions between strings and row of bytes
|
||||||
|
@ -10,27 +9,6 @@ conversions between strings and row of bytes
|
||||||
.nf
|
.nf
|
||||||
.B #include <ack_string.h>
|
.B #include <ack_string.h>
|
||||||
.PP
|
.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 *strindex(s, c)
|
||||||
.B char *s, c;
|
.B char *s, c;
|
||||||
.PP
|
.PP
|
||||||
|
@ -82,56 +60,6 @@ functions operate on variable-length rows of bytes,
|
||||||
regardless of null bytes.
|
regardless of null bytes.
|
||||||
Neither of these functions check for overflow of any receiving area.
|
Neither of these functions check for overflow of any receiving area.
|
||||||
.PP
|
.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
|
.I Strindex
|
||||||
.RI ( strrindex )
|
.RI ( strrindex )
|
||||||
returns a pointer to the first (last)
|
returns a pointer to the first (last)
|
||||||
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
|
@ -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;
|
|
||||||
}
|
|
Loading…
Reference in a new issue