From ac79a8c0ebce44313944033ddef7dd8eb5f9574a Mon Sep 17 00:00:00 2001 From: robert Date: Fri, 30 Aug 2002 19:42:07 +0000 Subject: - Update the manual pages of index() and rindex() to show as the associated header file. The prototypes have been moved there from because POSIX.1-2001 said so. - Conditionally include either or based on whether the [r]index() or str[r]chr() functions are compiled, respectively. - Style(9) tells us to - put a space after the return keyword - to check for a NUL character without using the ! operator. - use NULL instead of (type *)NULL where the compiler knows the type. Apply these rules. - Rather use ANSI-C function definitions than K&R ones. - For index(3), correct second function argument's type; it was declared to be a `const char' before and is now an `int'. --- lib/libc/string/index.3 | 9 ++++++++- lib/libc/string/index.c | 20 ++++++++++++-------- lib/libc/string/rindex.3 | 9 ++++++++- lib/libc/string/rindex.c | 17 ++++++++++------- 4 files changed, 38 insertions(+), 17 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/string/index.3 b/lib/libc/string/index.3 index 902b19c..0102fa6 100644 --- a/lib/libc/string/index.3 +++ b/lib/libc/string/index.3 @@ -43,7 +43,7 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In string.h +.In strings.h .Ft char * .Fn index "const char *s" "int c" .Sh DESCRIPTION @@ -81,3 +81,10 @@ A .Fn index function appeared in .At v6 . +Its prototype existed previously in +.Aq Pa string.h +before it was moved to +.Aq Pa strings.h +for +.St -p1003.1-2001 +compliance. diff --git a/lib/libc/string/index.c b/lib/libc/string/index.c index 7eaf3d7..c81f95b 100644 --- a/lib/libc/string/index.c +++ b/lib/libc/string/index.c @@ -37,22 +37,26 @@ static char sccsid[] = "@(#)index.c 8.1 (Berkeley) 6/4/93"; #include __FBSDID("$FreeBSD$"); -#include #include -char * #ifdef STRCHR -strchr(p, ch) +#include + +char * +strchr #else -index(p, ch) +#include + +char * +index #endif - const char *p, ch; +(const char *p, int ch) { for (;; ++p) { if (*p == ch) - return((char *)p); - if (!*p) - return((char *)NULL); + return ((char *)p); + if (*p == '\0') + return (NULL); } /* NOTREACHED */ } diff --git a/lib/libc/string/rindex.3 b/lib/libc/string/rindex.3 index b5ffd1c..954f126 100644 --- a/lib/libc/string/rindex.3 +++ b/lib/libc/string/rindex.3 @@ -43,7 +43,7 @@ .Sh LIBRARY .Lb libc .Sh SYNOPSIS -.In string.h +.In strings.h .Ft char * .Fn rindex "const char *s" "int c" .Sh DESCRIPTION @@ -83,3 +83,10 @@ A .Fn rindex function appeared in .At v6 . +Its prototype existed previously in +.Aq Pa string.h +before it was moved to +.Aq Pa strings.h +for +.St -p1003.1-2001 +compliance. diff --git a/lib/libc/string/rindex.c b/lib/libc/string/rindex.c index 1b08dd1..d0be32e 100644 --- a/lib/libc/string/rindex.c +++ b/lib/libc/string/rindex.c @@ -38,24 +38,27 @@ static char sccsid[] = "@(#)rindex.c 8.1 (Berkeley) 6/4/93"; __FBSDID("$FreeBSD$"); #include + +#ifdef STRRCHR #include char * -#ifdef STRRCHR -strrchr(p, ch) +strrchr #else -rindex(p, ch) +#include + +char * +rindex #endif - const char *p; - int ch; +(const char *p, int ch) { char *save; for (save = NULL;; ++p) { if (*p == ch) save = (char *)p; - if (!*p) - return(save); + if (*p == '\0') + return (save); } /* NOTREACHED */ } -- cgit v1.1