aboutsummaryrefslogtreecommitdiff
path: root/src/core/ngx_string.c
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/core/ngx_string.c
parent3ca4061874dc70319eb5358724addf0fd64de6fe (diff)
downloadnginx-d2b687cf3fd84f890504de2650e3cdfc678cf360.tar.gz
nginx-d2b687cf3fd84f890504de2650e3cdfc678cf360.zip
ngx_atofp()
Diffstat (limited to 'src/core/ngx_string.c')
-rw-r--r--src/core/ngx_string.c50
1 files changed, 50 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)
{