Klaus Demo nginx / d2b687c
ngx_atofp() Igor Sysoev 12 years ago
2 changed file(s) with 51 addition(s) and 0 deletion(s). Raw diff Collapse all Expand all
876876 }
877877
878878
879 /* parse a fixed point number, e.g., ngx_atofp("10.5", 4, 2) returns 1050 */
880
881 ngx_int_t
882 ngx_atofp(u_char *line, size_t n, size_t point)
883 {
884 ngx_int_t value;
885 ngx_uint_t dot;
886
887 if (n == 0) {
888 return NGX_ERROR;
889 }
890
891 dot = 0;
892
893 for (value = 0; n--; line++) {
894
895 if (point == 0) {
896 return NGX_ERROR;
897 }
898
899 if (*line == '.') {
900 if (dot) {
901 return NGX_ERROR;
902 }
903
904 dot = 1;
905 continue;
906 }
907
908 if (*line < '0' || *line > '9') {
909 return NGX_ERROR;
910 }
911
912 value = value * 10 + (*line - '0');
913 point -= dot;
914 }
915
916 while (point--) {
917 value = value * 10;
918 }
919
920 if (value < 0) {
921 return NGX_ERROR;
922
923 } else {
924 return value;
925 }
926 }
927
928
879929 ssize_t
880930 ngx_atosz(u_char *line, size_t n)
881931 {
160160 ngx_int_t ngx_dns_strcmp(u_char *s1, u_char *s2);
161161
162162 ngx_int_t ngx_atoi(u_char *line, size_t n);
163 ngx_int_t ngx_atofp(u_char *line, size_t n, size_t point);
163164 ssize_t ngx_atosz(u_char *line, size_t n);
164165 off_t ngx_atoof(u_char *line, size_t n);
165166 time_t ngx_atotm(u_char *line, size_t n);