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:
parent
f4e110ebf2
commit
e97a378b02
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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. */
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user