summaryrefslogtreecommitdiffstats
path: root/sys/libkern
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1999-11-21 04:26:48 +0000
committerpeter <peter@FreeBSD.org>1999-11-21 04:26:48 +0000
commit216e35006e551f69144762215a7ef9762298fe98 (patch)
tree408c546667ad68d073b739a9fae743a2cc3c218a /sys/libkern
parentbc517213b48aad16f9ee93b012cb65efddcc204c (diff)
downloadFreeBSD-src-216e35006e551f69144762215a7ef9762298fe98.zip
FreeBSD-src-216e35006e551f69144762215a7ef9762298fe98.tar.gz
Tempt fate and stop index from converting a const char * into a char *.
I've made a seperate version (c_index() etc) that use const/const, but I'm not sure it's worth it considering there is one file in the tree that uses index on const strings (kern_linker.c) and it's easily adjusted to scan the strings directly (and is perhaps more efficient that way).
Diffstat (limited to 'sys/libkern')
-rw-r--r--sys/libkern/index.c28
-rw-r--r--sys/libkern/rindex.c32
2 files changed, 42 insertions, 18 deletions
diff --git a/sys/libkern/index.c b/sys/libkern/index.c
index 6351223..b22341c 100644
--- a/sys/libkern/index.c
+++ b/sys/libkern/index.c
@@ -33,21 +33,33 @@
* $FreeBSD$
*/
-#include <string.h>
+#include <sys/param.h>
+#include <sys/libkern.h>
char *
-#ifdef STRCHR
-strchr(p, ch)
-#else
index(p, ch)
-#endif
- register const char *p, ch;
+ char *p;
+ int ch;
{
for (;; ++p) {
if (*p == ch)
- return((char *)p);
+ return(p);
if (!*p)
- return((char *)NULL);
+ return(NULL);
+ }
+ /* NOTREACHED */
+}
+
+const char *
+c_index(p, ch)
+ const char *p;
+ int ch;
+{
+ for (;; ++p) {
+ if (*p == ch)
+ return(p);
+ if (!*p)
+ return(NULL);
}
/* NOTREACHED */
}
diff --git a/sys/libkern/rindex.c b/sys/libkern/rindex.c
index f51abcc..b73031c 100644
--- a/sys/libkern/rindex.c
+++ b/sys/libkern/rindex.c
@@ -33,23 +33,35 @@
* $FreeBSD$
*/
-#include <stddef.h>
-#include <string.h>
+#include <sys/param.h>
+#include <sys/libkern.h>
char *
-#ifdef STRRCHR
-strrchr(p, ch)
-#else
rindex(p, ch)
-#endif
- register const char *p;
- register int ch;
+ char *p;
+ int ch;
{
- register char *save;
+ char *save;
for (save = NULL;; ++p) {
if (*p == ch)
- save = (char *)p;
+ save = p;
+ if (!*p)
+ return(save);
+ }
+ /* NOTREACHED */
+}
+
+const char *
+c_rindex(p, ch)
+ const char *p;
+ int ch;
+{
+ const char *save;
+
+ for (save = NULL;; ++p) {
+ if (*p == ch)
+ save = p;
if (!*p)
return(save);
}
OpenPOWER on IntegriCloud