From 37cc165064fd681ef453c59e28a9170d3338979a Mon Sep 17 00:00:00 2001 From: Igor Sysoev Date: Fri, 12 Jan 2007 20:15:59 +0000 Subject: [PATCH] ngx_strn2cmp() --- src/core/ngx_string.c | 25 +++++++++++++++++++++++++ src/core/ngx_string.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c index ad2c9d8c8..2b2396052 100644 --- a/src/core/ngx_string.c +++ b/src/core/ngx_string.c @@ -486,6 +486,31 @@ ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n) } +ngx_int_t +ngx_strn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2) +{ + size_t n; + ngx_int_t m, z; + + if (n1 <= n2) { + n = n1; + z = -1; + + } else { + n = n2; + z = 1; + } + + m = ngx_strncmp(s1, s2, n); + + if (m || n1 == n2) { + return m; + } + + return z; +} + + ngx_int_t ngx_atoi(u_char *line, size_t n) { diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h index 10f87ae93..1dd8b549f 100644 --- a/src/core/ngx_string.h +++ b/src/core/ngx_string.h @@ -130,6 +130,7 @@ u_char *ngx_vsnprintf(u_char *buf, size_t max, const char *fmt, va_list args); ngx_int_t ngx_rstrncmp(u_char *s1, u_char *s2, size_t n); ngx_int_t ngx_rstrncasecmp(u_char *s1, u_char *s2, size_t n); +ngx_int_t ngx_strn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2); ngx_int_t ngx_atoi(u_char *line, size_t n); ssize_t ngx_atosz(u_char *line, size_t n);