aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIgor Sysoev <igor@sysoev.ru>2010-05-14 09:01:30 +0000
committerIgor Sysoev <igor@sysoev.ru>2010-05-14 09:01:30 +0000
commitd2b687cf3fd84f890504de2650e3cdfc678cf360 (patch)
treea2b8b2b8c297233366ccff1bf88e9c31335ea932 /src
parent3ca4061874dc70319eb5358724addf0fd64de6fe (diff)
downloadnginx-d2b687cf3fd84f890504de2650e3cdfc678cf360.tar.gz
nginx-d2b687cf3fd84f890504de2650e3cdfc678cf360.zip
ngx_atofp()
Diffstat (limited to 'src')
-rw-r--r--src/core/ngx_string.c50
-rw-r--r--src/core/ngx_string.h1
2 files changed, 51 insertions, 0 deletions
diff --git a/src/core/ngx_string.c b/src/core/ngx_string.c
index 5cf505aa1..f513753a1 100644
--- a/src/core/ngx_string.c
+++ b/src/core/ngx_string.c
@@ -877,6 +877,56 @@ ngx_atoi(u_char *line, size_t n)
}
+/* parse a fixed point number, e.g., ngx_atofp("10.5", 4, 2) returns 1050 */
+
+ngx_int_t
+ngx_atofp(u_char *line, size_t n, size_t point)
+{
+ ngx_int_t value;
+ ngx_uint_t dot;
+
+ if (n == 0) {
+ return NGX_ERROR;
+ }
+
+ dot = 0;
+
+ for (value = 0; n--; line++) {
+
+ if (point == 0) {
+ return NGX_ERROR;
+ }
+
+ if (*line == '.') {
+ if (dot) {
+ return NGX_ERROR;
+ }
+
+ dot = 1;
+ continue;
+ }
+
+ if (*line < '0' || *line > '9') {
+ return NGX_ERROR;
+ }
+
+ value = value * 10 + (*line - '0');
+ point -= dot;
+ }
+
+ while (point--) {
+ value = value * 10;
+ }
+
+ if (value < 0) {
+ return NGX_ERROR;
+
+ } else {
+ return value;
+ }
+}
+
+
ssize_t
ngx_atosz(u_char *line, size_t n)
{
diff --git a/src/core/ngx_string.h b/src/core/ngx_string.h
index 0525b0e24..b29bdda3d 100644
--- a/src/core/ngx_string.h
+++ b/src/core/ngx_string.h
@@ -161,6 +161,7 @@ ngx_int_t ngx_memn2cmp(u_char *s1, u_char *s2, size_t n1, size_t n2);
ngx_int_t ngx_dns_strcmp(u_char *s1, u_char *s2);
ngx_int_t ngx_atoi(u_char *line, size_t n);
+ngx_int_t ngx_atofp(u_char *line, size_t n, size_t point);
ssize_t ngx_atosz(u_char *line, size_t n);
off_t ngx_atoof(u_char *line, size_t n);
time_t ngx_atotm(u_char *line, size_t n);