summaryrefslogtreecommitdiffstats
path: root/lib/libc/string/index.c
diff options
context:
space:
mode:
authorrobert <robert@FreeBSD.org>2002-08-30 19:42:07 +0000
committerrobert <robert@FreeBSD.org>2002-08-30 19:42:07 +0000
commitac79a8c0ebce44313944033ddef7dd8eb5f9574a (patch)
tree73cc35c843328d5541c417f0803442e2f6f05d29 /lib/libc/string/index.c
parent6700ee6cc9a1c5872f179da0e7d16a1b0c35b4ea (diff)
downloadFreeBSD-src-ac79a8c0ebce44313944033ddef7dd8eb5f9574a.zip
FreeBSD-src-ac79a8c0ebce44313944033ddef7dd8eb5f9574a.tar.gz
- Update the manual pages of index() and rindex() to show
<strings.h> as the associated header file. The prototypes have been moved there from <string.h> because POSIX.1-2001 said so. - Conditionally include either <strings.h> or <string.h> 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'.
Diffstat (limited to 'lib/libc/string/index.c')
-rw-r--r--lib/libc/string/index.c20
1 files changed, 12 insertions, 8 deletions
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 <sys/cdefs.h>
__FBSDID("$FreeBSD$");
-#include <string.h>
#include <stddef.h>
-char *
#ifdef STRCHR
-strchr(p, ch)
+#include <string.h>
+
+char *
+strchr
#else
-index(p, ch)
+#include <strings.h>
+
+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 */
}
OpenPOWER on IntegriCloud