comparison src/core/ngx_string.c @ 1552:f045c67ab622

ngx_strnstr()
author Igor Sysoev <igor@sysoev.ru>
date Mon, 01 Oct 2007 14:48:33 +0000
parents d0bdd5f2276e
children 25ee6eee7573
comparison
equal deleted inserted replaced
1551:9ea31a2eab27 1552:f045c67ab622
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 */