strchr() and strrchr() are already present in the kernel, but with less

popular names. Hence:

- comment current index() and rindex() functions, as these serve the same
  functionality as, respectively, strchr() and strrchr() from userland;
- add inlined version of strchr() and strrchr(), as we tend to use them more
  often;
- remove str[r]chr() definitions from ZFS code;

Reviewed by:	pjd
Approved by:	cognet (mentor)
This commit is contained in:
wkoszek 2007-04-10 21:42:12 +00:00
parent f4e110ebf2
commit e97a378b02
7 changed files with 24 additions and 66 deletions

View File

@ -31,37 +31,6 @@
#define IS_ALPHA(c) \
(((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z'))
char *
strchr(const char *s, int c)
{
char ch;
ch = c;
for (;; ++s) {
if (*s == ch)
return ((char *)s);
if (*s == '\0')
return (NULL);
}
/* NOTREACHED */
}
char *
strrchr(const char *s, int c)
{
char *save;
char ch;
ch = c;
for (save = NULL;; ++s) {
if (*s == ch)
save = (char *)s;
if (*s == '\0')
return (save);
}
/* NOTREACHED */
}
char *
strpbrk(const char *s, const char *b)
{

View File

@ -29,8 +29,8 @@
#ifndef _OPENSOLARIS_SYS_STRING_H_
#define _OPENSOLARIS_SYS_STRING_H_
char *strchr(const char *, int);
char *strrchr(const char *p, int c);
#include <sys/libkern.h>
char *strpbrk(const char *, const char *);
void strident_canon(char *s, size_t n);

View File

@ -31,37 +31,6 @@
#define IS_ALPHA(c) \
(((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z'))
char *
strchr(const char *s, int c)
{
char ch;
ch = c;
for (;; ++s) {
if (*s == ch)
return ((char *)s);
if (*s == '\0')
return (NULL);
}
/* NOTREACHED */
}
char *
strrchr(const char *s, int c)
{
char *save;
char ch;
ch = c;
for (save = NULL;; ++s) {
if (*s == ch)
save = (char *)s;
if (*s == '\0')
return (save);
}
/* NOTREACHED */
}
char *
strpbrk(const char *s, const char *b)
{

View File

@ -29,8 +29,8 @@
#ifndef _OPENSOLARIS_SYS_STRING_H_
#define _OPENSOLARIS_SYS_STRING_H_
char *strchr(const char *, int);
char *strrchr(const char *p, int c);
#include <sys/libkern.h>
char *strpbrk(const char *, const char *);
void strident_canon(char *s, size_t n);

View File

@ -33,6 +33,10 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/libkern.h>
/*
* index() is also present as the strchr() in the kernel; it does exactly the
* same thing as it's userland equivalent.
*/
char *
index(p, ch)
const char *p;

View File

@ -33,6 +33,10 @@ __FBSDID("$FreeBSD$");
#include <sys/param.h>
#include <sys/libkern.h>
/*
* rindex() is also present as the strrchr() in the kernel; it does exactly the
* same thing as it's userland equivalent.
*/
char *
rindex(p, ch)
const char *p;

View File

@ -153,6 +153,18 @@ memset(void *b, int c, size_t len)
return (b);
}
static __inline char *
strchr(const char *p, int ch)
{
return (index(p, ch));
}
static __inline char *
strrchr(const char *p, int ch)
{
return (rindex(p, ch));
}
/* fnmatch() return values. */
#define FNM_NOMATCH 1 /* Match failed. */