mirror of
https://github.com/nginx/nginx.git
synced 2024-12-04 13:59:00 +08:00
ngx_atofp()
This commit is contained in:
parent
3ca4061874
commit
d2b687cf3f
@ -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)
|
||||
{
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user