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).
This commit is contained in:
parent
75099bed2f
commit
95dc37f68d
@ -345,7 +345,7 @@ linker_make_file(const char* pathname, void* priv, struct linker_file_ops* ops)
|
||||
int namelen;
|
||||
const char *filename;
|
||||
|
||||
filename = rindex(pathname, '/');
|
||||
filename = c_rindex(pathname, '/');
|
||||
if (filename && filename[1])
|
||||
filename++;
|
||||
else
|
||||
@ -993,7 +993,7 @@ linker_search_path(const char *name)
|
||||
enum vtype type;
|
||||
|
||||
/* qualified at all? */
|
||||
if (index(name, '/'))
|
||||
if (c_index(name, '/'))
|
||||
return(linker_strdup(name));
|
||||
|
||||
/* traverse the linker path */
|
||||
|
@ -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 */
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -72,8 +72,10 @@ int locc __P((int, char *, u_int));
|
||||
void qsort __P((void *base, size_t nmemb, size_t size,
|
||||
int (*compar)(const void *, const void *)));
|
||||
u_long random __P((void));
|
||||
char *index __P((const char *, int));
|
||||
char *rindex __P((const char *, int));
|
||||
char *index __P((char *, int));
|
||||
char *rindex __P((char *, int));
|
||||
const char *c_index __P((const char *, int));
|
||||
const char *c_rindex __P((const char *, int));
|
||||
int scanc __P((u_int, const u_char *, const u_char *, int));
|
||||
int skpc __P((int, int, char *));
|
||||
void srandom __P((u_long));
|
||||
|
Loading…
x
Reference in New Issue
Block a user