From ff17de3853153fe69601eac8e59ac2cddc50408a Mon Sep 17 00:00:00 2001 From: danger Date: Tue, 3 Feb 2009 17:58:20 +0000 Subject: - ANSIfy function definitions - use nul when we are looking for a terminating character where appropriate Approved by: imp --- lib/libc/string/memccpy.c | 6 +----- lib/libc/string/memchr.c | 5 +---- lib/libc/string/memcmp.c | 4 +--- lib/libc/string/memmem.c | 4 +--- lib/libc/string/strcasecmp.c | 7 ++----- lib/libc/string/strcasestr.c | 3 +-- lib/libc/string/strcmp.c | 5 ++--- lib/libc/string/strcoll.c | 3 +-- lib/libc/string/strdup.c | 3 +-- lib/libc/string/strmode.c | 4 +--- lib/libc/string/strncmp.c | 6 ++---- lib/libc/string/strncpy.c | 4 ++-- lib/libc/string/strnstr.c | 5 +---- lib/libc/string/strpbrk.c | 5 ++--- lib/libc/string/strsep.c | 4 +--- lib/libc/string/strstr.c | 7 +++---- lib/libc/string/wcscat.c | 4 +--- lib/libc/string/wcscmp.c | 5 ++--- lib/libc/string/wcscpy.c | 4 +--- lib/libc/string/wcscspn.c | 4 +--- lib/libc/string/wcslcat.c | 5 +---- lib/libc/string/wcslcpy.c | 5 +---- lib/libc/string/wcslen.c | 3 +-- lib/libc/string/wcsncat.c | 5 +---- lib/libc/string/wcsncmp.c | 4 +--- lib/libc/string/wcspbrk.c | 4 +--- lib/libc/string/wcsspn.c | 4 +--- lib/libc/string/wcsstr.c | 2 +- lib/libc/string/wmemchr.c | 5 +---- lib/libc/string/wmemcmp.c | 5 +---- lib/libc/string/wmemcpy.c | 6 +----- lib/libc/string/wmemmove.c | 6 +----- lib/libc/string/wmemset.c | 5 +---- 33 files changed, 41 insertions(+), 110 deletions(-) diff --git a/lib/libc/string/memccpy.c b/lib/libc/string/memccpy.c index 5b4223e..539d33e 100644 --- a/lib/libc/string/memccpy.c +++ b/lib/libc/string/memccpy.c @@ -36,11 +36,7 @@ __FBSDID("$FreeBSD$"); #include 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) { diff --git a/lib/libc/string/memchr.c b/lib/libc/string/memchr.c index 2b1231d..47d37db 100644 --- a/lib/libc/string/memchr.c +++ b/lib/libc/string/memchr.c @@ -39,10 +39,7 @@ __FBSDID("$FreeBSD$"); #include 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; diff --git a/lib/libc/string/memcmp.c b/lib/libc/string/memcmp.c index d048068..4a1b66e 100644 --- a/lib/libc/string/memcmp.c +++ b/lib/libc/string/memcmp.c @@ -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; diff --git a/lib/libc/string/memmem.c b/lib/libc/string/memmem.c index 0ac0a6d..72e6517 100644 --- a/lib/libc/string/memmem.c +++ b/lib/libc/string/memmem.c @@ -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; diff --git a/lib/libc/string/strcasecmp.c b/lib/libc/string/strcasecmp.c index 2efcf55..4a474fe 100644 --- a/lib/libc/string/strcasecmp.c +++ b/lib/libc/string/strcasecmp.c @@ -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 diff --git a/lib/libc/string/strcasestr.c b/lib/libc/string/strcasestr.c index b358b7d..9b28bf5 100644 --- a/lib/libc/string/strcasestr.c +++ b/lib/libc/string/strcasestr.c @@ -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; diff --git a/lib/libc/string/strcmp.c b/lib/libc/string/strcmp.c index ab95333..95c778d 100644 --- a/lib/libc/string/strcmp.c +++ b/lib/libc/string/strcmp.c @@ -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)); } diff --git a/lib/libc/string/strcoll.c b/lib/libc/string/strcoll.c index a0daf8d..0da5c57 100644 --- a/lib/libc/string/strcoll.c +++ b/lib/libc/string/strcoll.c @@ -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; diff --git a/lib/libc/string/strdup.c b/lib/libc/string/strdup.c index c0b581d..570ad83 100644 --- a/lib/libc/string/strdup.c +++ b/lib/libc/string/strdup.c @@ -38,8 +38,7 @@ __FBSDID("$FreeBSD$"); #include char * -strdup(str) - const char *str; +strdup(const char *str) { size_t len; char *copy; diff --git a/lib/libc/string/strmode.c b/lib/libc/string/strmode.c index be09d7a..855e1b5 100644 --- a/lib/libc/string/strmode.c +++ b/lib/libc/string/strmode.c @@ -38,9 +38,7 @@ __FBSDID("$FreeBSD$"); #include void -strmode(mode, p) - mode_t mode; - char *p; +strmode(mode_t mode, char *p) { /* print type */ switch (mode & S_IFMT) { diff --git a/lib/libc/string/strncmp.c b/lib/libc/string/strncmp.c index 659a7cb..5bc3d5e 100644 --- a/lib/libc/string/strncmp.c +++ b/lib/libc/string/strncmp.c @@ -36,9 +36,7 @@ __FBSDID("$FreeBSD$"); #include 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); diff --git a/lib/libc/string/strncpy.c b/lib/libc/string/strncpy.c index 07b9166..980dbc7 100644 --- a/lib/libc/string/strncpy.c +++ b/lib/libc/string/strncpy.c @@ -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); diff --git a/lib/libc/string/strnstr.c b/lib/libc/string/strnstr.c index bbb1ca6..45be95d 100644 --- a/lib/libc/string/strnstr.c +++ b/lib/libc/string/strnstr.c @@ -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; diff --git a/lib/libc/string/strpbrk.c b/lib/libc/string/strpbrk.c index efbdc8a..2069bee 100644 --- a/lib/libc/string/strpbrk.c +++ b/lib/libc/string/strpbrk.c @@ -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)); } diff --git a/lib/libc/string/strsep.c b/lib/libc/string/strsep.c index 0850b0b..670ab04 100644 --- a/lib/libc/string/strsep.c +++ b/lib/libc/string/strsep.c @@ -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; diff --git a/lib/libc/string/strstr.c b/lib/libc/string/strstr.c index e2edd80..82b4c5a 100644 --- a/lib/libc/string/strstr.c +++ b/lib/libc/string/strstr.c @@ -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); diff --git a/lib/libc/string/wcscat.c b/lib/libc/string/wcscat.c index 1c96533..7ae4e80 100644 --- a/lib/libc/string/wcscat.c +++ b/lib/libc/string/wcscat.c @@ -37,9 +37,7 @@ __FBSDID("$FreeBSD$"); #include 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; diff --git a/lib/libc/string/wcscmp.c b/lib/libc/string/wcscmp.c index 59c3eef..2d48914 100644 --- a/lib/libc/string/wcscmp.c +++ b/lib/libc/string/wcscmp.c @@ -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); diff --git a/lib/libc/string/wcscpy.c b/lib/libc/string/wcscpy.c index 180bbd1..0c6e1f2 100644 --- a/lib/libc/string/wcscpy.c +++ b/lib/libc/string/wcscpy.c @@ -37,9 +37,7 @@ __FBSDID("$FreeBSD$"); #include 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; diff --git a/lib/libc/string/wcscspn.c b/lib/libc/string/wcscspn.c index 57a804c..7729dc8 100644 --- a/lib/libc/string/wcscspn.c +++ b/lib/libc/string/wcscspn.c @@ -37,9 +37,7 @@ __FBSDID("$FreeBSD$"); #include 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; diff --git a/lib/libc/string/wcslcat.c b/lib/libc/string/wcslcat.c index 6466f06..f5f1e1e 100644 --- a/lib/libc/string/wcslcat.c +++ b/lib/libc/string/wcslcat.c @@ -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; diff --git a/lib/libc/string/wcslcpy.c b/lib/libc/string/wcslcpy.c index 1b9459a..b104a06 100644 --- a/lib/libc/string/wcslcpy.c +++ b/lib/libc/string/wcslcpy.c @@ -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; diff --git a/lib/libc/string/wcslen.c b/lib/libc/string/wcslen.c index 1636d98..ca3004e 100644 --- a/lib/libc/string/wcslen.c +++ b/lib/libc/string/wcslen.c @@ -37,8 +37,7 @@ __FBSDID("$FreeBSD$"); #include size_t -wcslen(s) - const wchar_t *s; +wcslen(const wchar_t *s) { const wchar_t *p; diff --git a/lib/libc/string/wcsncat.c b/lib/libc/string/wcsncat.c index ba49a9e..44f1ff9 100644 --- a/lib/libc/string/wcsncat.c +++ b/lib/libc/string/wcsncat.c @@ -37,10 +37,7 @@ __FBSDID("$FreeBSD$"); #include 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; diff --git a/lib/libc/string/wcsncmp.c b/lib/libc/string/wcsncmp.c index 5b7b3ee..86d7a51 100644 --- a/lib/libc/string/wcsncmp.c +++ b/lib/libc/string/wcsncmp.c @@ -39,9 +39,7 @@ __FBSDID("$FreeBSD$"); #include 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) diff --git a/lib/libc/string/wcspbrk.c b/lib/libc/string/wcspbrk.c index 7315c44..2ff71ba 100644 --- a/lib/libc/string/wcspbrk.c +++ b/lib/libc/string/wcspbrk.c @@ -37,9 +37,7 @@ __FBSDID("$FreeBSD$"); #include 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; diff --git a/lib/libc/string/wcsspn.c b/lib/libc/string/wcsspn.c index 584a9d3..6569206 100644 --- a/lib/libc/string/wcsspn.c +++ b/lib/libc/string/wcsspn.c @@ -37,9 +37,7 @@ __FBSDID("$FreeBSD$"); #include 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; diff --git a/lib/libc/string/wcsstr.c b/lib/libc/string/wcsstr.c index b8a7598..a9dc27b 100644 --- a/lib/libc/string/wcsstr.c +++ b/lib/libc/string/wcsstr.c @@ -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 { diff --git a/lib/libc/string/wmemchr.c b/lib/libc/string/wmemchr.c index 2d96708..cab89c9 100644 --- a/lib/libc/string/wmemchr.c +++ b/lib/libc/string/wmemchr.c @@ -37,10 +37,7 @@ __FBSDID("$FreeBSD$"); #include 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; diff --git a/lib/libc/string/wmemcmp.c b/lib/libc/string/wmemcmp.c index c9a9095..fdb1f986 100644 --- a/lib/libc/string/wmemcmp.c +++ b/lib/libc/string/wmemcmp.c @@ -37,10 +37,7 @@ __FBSDID("$FreeBSD$"); #include 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; diff --git a/lib/libc/string/wmemcpy.c b/lib/libc/string/wmemcpy.c index 38d563d..c10770c 100644 --- a/lib/libc/string/wmemcpy.c +++ b/lib/libc/string/wmemcpy.c @@ -38,11 +38,7 @@ __FBSDID("$FreeBSD$"); #include 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)); } diff --git a/lib/libc/string/wmemmove.c b/lib/libc/string/wmemmove.c index 6b3ee94..05cfd10 100644 --- a/lib/libc/string/wmemmove.c +++ b/lib/libc/string/wmemmove.c @@ -38,11 +38,7 @@ __FBSDID("$FreeBSD$"); #include 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)); } diff --git a/lib/libc/string/wmemset.c b/lib/libc/string/wmemset.c index b923f14..362bdf2 100644 --- a/lib/libc/string/wmemset.c +++ b/lib/libc/string/wmemset.c @@ -37,10 +37,7 @@ __FBSDID("$FreeBSD$"); #include 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; -- cgit v1.1