ngx_strnstr()

This commit is contained in:
Igor Sysoev 2007-10-01 14:48:33 +00:00
parent 834e447234
commit 35fe5fd06d
2 changed files with 36 additions and 0 deletions

View File

@ -503,6 +503,40 @@ ngx_strncasecmp(u_char *s1, u_char *s2, size_t n)
}
u_char *
ngx_strnstr(u_char *s1, char *s2, size_t len)
{
u_char c1, c2;
size_t n;
c2 = *(u_char *) s2++;
n = ngx_strlen(s2);
do {
do {
if (len-- == 0) {
return NULL;
}
c1 = *s1++;
if (c1 == 0) {
return NULL;
}
} while (c1 != c2);
if (n > len) {
return NULL;
}
} while (ngx_strncmp(s1, (u_char *) s2, n) != 0);
return --s1;
}
/*
* ngx_strstrn() and ngx_strcasestrn() are intended to search for static
* substring with known length in null-terminated string. The argument n

View File

@ -126,6 +126,8 @@ u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args);
ngx_int_t ngx_strcasecmp(u_char *s1, u_char *s2);
ngx_int_t ngx_strncasecmp(u_char *s1, u_char *s2, size_t n);
u_char *ngx_strnstr(u_char *s1, char *s2, size_t n);
u_char *ngx_strstrn(u_char *s1, char *s2, size_t n);
u_char *ngx_strcasestrn(u_char *s1, char *s2, size_t n);