Mercurial > hg > nginx
comparison src/core/ngx_string.c @ 1615:ca6845b19113 stable-0.5
r1553, r1554 merge:
ngx_strnstr()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 29 Oct 2007 15:10:31 +0000 |
parents | d72f8b48dd87 |
children | d2a12e9a34e8 |
comparison
equal
deleted
inserted
replaced
1614:a0ec4734d2e9 | 1615:ca6845b19113 |
---|---|
501 | 501 |
502 return 0; | 502 return 0; |
503 } | 503 } |
504 | 504 |
505 | 505 |
506 u_char * | |
507 ngx_strnstr(u_char *s1, char *s2, size_t len) | |
508 { | |
509 u_char c1, c2; | |
510 size_t n; | |
511 | |
512 c2 = *(u_char *) s2++; | |
513 | |
514 n = ngx_strlen(s2); | |
515 | |
516 do { | |
517 do { | |
518 if (len-- == 0) { | |
519 return NULL; | |
520 } | |
521 | |
522 c1 = *s1++; | |
523 | |
524 if (c1 == 0) { | |
525 return NULL; | |
526 } | |
527 | |
528 } while (c1 != c2); | |
529 | |
530 if (n > len) { | |
531 return NULL; | |
532 } | |
533 | |
534 } while (ngx_strncmp(s1, (u_char *) s2, n) != 0); | |
535 | |
536 return --s1; | |
537 } | |
538 | |
539 | |
506 /* | 540 /* |
507 * ngx_strstrn() and ngx_strcasestrn() are intended to search for static | 541 * ngx_strstrn() and ngx_strcasestrn() are intended to search for static |
508 * substring with known length in null-terminated string. The argument n | 542 * substring with known length in null-terminated string. The argument n |
509 * must be length of the second substring - 1. | 543 * must be length of the second substring - 1. |
510 */ | 544 */ |