- ANSIfy function definitions

- use nul when we are looking for a terminating character where appropriate

Approved by:	imp
This commit is contained in:
Daniel Gerzo 2009-02-03 17:58:20 +00:00
parent 23ee18767e
commit bd604b4b06
33 changed files with 41 additions and 110 deletions

View File

@ -36,11 +36,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
void *
memccpy(t, f, c, n)
void *t;
const void *f;
int c;
size_t n;
memccpy(void *t, const void *f, int c, size_t n)
{
if (n) {

View File

@ -39,10 +39,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
void *
memchr(s, c, n)
const void *s;
unsigned char c;
size_t n;
memchr(const void *s, unsigned char c, size_t n)
{
if (n != 0) {
const unsigned char *p = s;

View File

@ -42,9 +42,7 @@ __FBSDID("$FreeBSD$");
* Compare memory regions.
*/
int
memcmp(s1, s2, n)
const void *s1, *s2;
size_t n;
memcmp(const void *s1, const void *s2, size_t n)
{
if (n != 0) {
const unsigned char *p1 = s1, *p2 = s2;

View File

@ -36,9 +36,7 @@ __FBSDID("$FreeBSD$");
*/
void *
memmem(l, l_len, s, s_len)
const void *l; size_t l_len;
const void *s; size_t s_len;
memmem(const void *l, size_t l_len, const void *s, size_t s_len)
{
register char *cur, *last;
const char *cl = (const char *)l;

View File

@ -39,8 +39,7 @@ __FBSDID("$FreeBSD$");
typedef unsigned char u_char;
int
strcasecmp(s1, s2)
const char *s1, *s2;
strcasecmp(const char *s1, const char *s2)
{
const u_char
*us1 = (const u_char *)s1,
@ -53,9 +52,7 @@ strcasecmp(s1, s2)
}
int
strncasecmp(s1, s2, n)
const char *s1, *s2;
size_t n;
strncasecmp(const char *s1, const char *s2, size_t n)
{
if (n != 0) {
const u_char

View File

@ -40,8 +40,7 @@ __FBSDID("$FreeBSD$");
* Find the first occurrence of find in s, ignore case.
*/
char *
strcasestr(s, find)
const char *s, *find;
strcasestr(const char *s, const char *find)
{
char c, sc;
size_t len;

View File

@ -42,11 +42,10 @@ __FBSDID("$FreeBSD$");
* Compare strings.
*/
int
strcmp(s1, s2)
const char *s1, *s2;
strcmp(const char *s1, const char *s2)
{
while (*s1 == *s2++)
if (*s1++ == 0)
if (*s1++ == '\0')
return (0);
return (*(const unsigned char *)s1 - *(const unsigned char *)(s2 - 1));
}

View File

@ -33,8 +33,7 @@ __FBSDID("$FreeBSD$");
#include "collate.h"
int
strcoll(s, s2)
const char *s, *s2;
strcoll(const char *s, const char *s2)
{
int len, len2, prim, prim2, sec, sec2, ret, ret2;
const char *t, *t2;

View File

@ -38,8 +38,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
char *
strdup(str)
const char *str;
strdup(const char *str)
{
size_t len;
char *copy;

View File

@ -38,9 +38,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
void
strmode(mode, p)
mode_t mode;
char *p;
strmode(mode_t mode, char *p)
{
/* print type */
switch (mode & S_IFMT) {

View File

@ -36,9 +36,7 @@ __FBSDID("$FreeBSD$");
#include <string.h>
int
strncmp(s1, s2, n)
const char *s1, *s2;
size_t n;
strncmp(const char *s1, const char *s2, size_t n)
{
if (n == 0)
@ -47,7 +45,7 @@ strncmp(s1, s2, n)
if (*s1 != *s2++)
return (*(const unsigned char *)s1 -
*(const unsigned char *)(s2 - 1));
if (*s1++ == 0)
if (*s1++ == '\0')
break;
} while (--n != 0);
return (0);

View File

@ -50,10 +50,10 @@ strncpy(char * __restrict dst, const char * __restrict src, size_t n)
const char *s = src;
do {
if ((*d++ = *s++) == 0) {
if ((*d++ = *s++) == '\0') {
/* NUL pad the remaining n-1 bytes */
while (--n != 0)
*d++ = 0;
*d++ = '\0';
break;
}
} while (--n != 0);

View File

@ -44,10 +44,7 @@ __FBSDID("$FreeBSD$");
* first slen characters of s.
*/
char *
strnstr(s, find, slen)
const char *s;
const char *find;
size_t slen;
strnstr(const char *s, const char *find, size_t slen)
{
char c, sc;
size_t len;

View File

@ -39,14 +39,13 @@ __FBSDID("$FreeBSD$");
* Find the first occurrence in s1 of a character in s2 (excluding NUL).
*/
char *
strpbrk(s1, s2)
const char *s1, *s2;
strpbrk(const char *s1, const char *s2)
{
const char *scanp;
int c, sc;
while ((c = *s1++) != 0) {
for (scanp = s2; (sc = *scanp++) != 0;)
for (scanp = s2; (sc = *scanp++) != '\0';)
if (sc == c)
return ((char *)(s1 - 1));
}

View File

@ -48,9 +48,7 @@ __FBSDID("$FreeBSD$");
* If *stringp is NULL, strsep returns NULL.
*/
char *
strsep(stringp, delim)
char **stringp;
const char *delim;
strsep(char **stringp, const char *delim)
{
char *s;
const char *spanp;

View File

@ -42,17 +42,16 @@ __FBSDID("$FreeBSD$");
* Find the first occurrence of find in s.
*/
char *
strstr(s, find)
const char *s, *find;
strstr(const char *s, const char *find)
{
char c, sc;
size_t len;
if ((c = *find++) != 0) {
if ((c = *find++) != '\0') {
len = strlen(find);
do {
do {
if ((sc = *s++) == 0)
if ((sc = *s++) == '\0')
return (NULL);
} while (sc != c);
} while (strncmp(s, find, len) != 0);

View File

@ -37,9 +37,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
wchar_t *
wcscat(s1, s2)
wchar_t * __restrict s1;
const wchar_t * __restrict s2;
wcscat(wchar_t * __restrict s1, const wchar_t * __restrict s2)
{
wchar_t *cp;

View File

@ -45,12 +45,11 @@ __FBSDID("$FreeBSD$");
* Compare strings.
*/
int
wcscmp(s1, s2)
const wchar_t *s1, *s2;
wcscmp(const wchar_t *s1, const wchar_t *s2)
{
while (*s1 == *s2++)
if (*s1++ == 0)
if (*s1++ == '\0')
return (0);
/* XXX assumes wchar_t = int */
return (*(const unsigned int *)s1 - *(const unsigned int *)--s2);

View File

@ -37,9 +37,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
wchar_t *
wcscpy(s1, s2)
wchar_t * __restrict s1;
const wchar_t * __restrict s2;
wcscpy(wchar_t * __restrict s1, const wchar_t * __restrict s2)
{
wchar_t *cp;

View File

@ -37,9 +37,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
size_t
wcscspn(s, set)
const wchar_t *s;
const wchar_t *set;
wcscspn(const wchar_t *s, const wchar_t *set)
{
const wchar_t *p;
const wchar_t *q;

View File

@ -46,10 +46,7 @@ __FBSDID("$FreeBSD$");
* truncation occurred.
*/
size_t
wcslcat(dst, src, siz)
wchar_t *dst;
const wchar_t *src;
size_t siz;
wcslcat(wchar_t *dst, const wchar_t *src, size_t siz)
{
wchar_t *d = dst;
const wchar_t *s = src;

View File

@ -44,10 +44,7 @@ __FBSDID("$FreeBSD$");
* Returns wcslen(src); if retval >= siz, truncation occurred.
*/
size_t
wcslcpy(dst, src, siz)
wchar_t *dst;
const wchar_t *src;
size_t siz;
wcslcpy(wchar_t *dst, const wchar_t *src, size_t siz)
{
wchar_t *d = dst;
const wchar_t *s = src;

View File

@ -37,8 +37,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
size_t
wcslen(s)
const wchar_t *s;
wcslen(const wchar_t *s)
{
const wchar_t *p;

View File

@ -37,10 +37,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
wchar_t *
wcsncat(s1, s2, n)
wchar_t * __restrict s1;
const wchar_t * __restrict s2;
size_t n;
wcsncat(wchar_t * __restrict s1, const wchar_t * __restrict s2, size_t n)
{
wchar_t *p;
wchar_t *q;

View File

@ -39,9 +39,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
int
wcsncmp(s1, s2, n)
const wchar_t *s1, *s2;
size_t n;
wcsncmp(const wchar_t *s1, const wchar_t *s2, size_t n)
{
if (n == 0)

View File

@ -37,9 +37,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
wchar_t *
wcspbrk(s, set)
const wchar_t *s;
const wchar_t *set;
wcspbrk(const wchar_t *s, const wchar_t *set)
{
const wchar_t *p;
const wchar_t *q;

View File

@ -37,9 +37,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
size_t
wcsspn(s, set)
const wchar_t *s;
const wchar_t *set;
wcsspn(const wchar_t *s, const wchar_t *set)
{
const wchar_t *p;
const wchar_t *q;

View File

@ -49,7 +49,7 @@ wcsstr(const wchar_t * __restrict s, const wchar_t * __restrict find)
wchar_t c, sc;
size_t len;
if ((c = *find++) != 0) {
if ((c = *find++) != L'\0') {
len = wcslen(find);
do {
do {

View File

@ -37,10 +37,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
wchar_t *
wmemchr(s, c, n)
const wchar_t *s;
wchar_t c;
size_t n;
wmemchr(const wchar_t *s, wchar_t c, size_t n)
{
size_t i;

View File

@ -37,10 +37,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
int
wmemcmp(s1, s2, n)
const wchar_t *s1;
const wchar_t *s2;
size_t n;
wmemcmp(const wchar_t *s1, const wchar_t *s2, size_t n)
{
size_t i;

View File

@ -38,11 +38,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
wchar_t *
wmemcpy(d, s, n)
wchar_t * __restrict d;
const wchar_t * __restrict s;
size_t n;
wmemcpy(wchar_t * __restrict d, const wchar_t * __restrict s, size_t n)
{
return (wchar_t *)memcpy(d, s, n * sizeof(wchar_t));
}

View File

@ -38,11 +38,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
wchar_t *
wmemmove(d, s, n)
wchar_t *d;
const wchar_t *s;
size_t n;
wmemmove(wchar_t *d, const wchar_t *s, size_t n)
{
return (wchar_t *)memmove(d, s, n * sizeof(wchar_t));
}

View File

@ -37,10 +37,7 @@ __FBSDID("$FreeBSD$");
#include <wchar.h>
wchar_t *
wmemset(s, c, n)
wchar_t *s;
wchar_t c;
size_t n;
wmemset(wchar_t *s, wchar_t *c, size_t n)
{
size_t i;
wchar_t *p;