Module: kamailio Branch: master Commit: b36da1dca71036ea3aa52675d3166317851e6594 URL: https://github.com/kamailio/kamailio/commit/b36da1dca71036ea3aa52675d3166317...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2019-11-26T08:49:02+01:00
core: utils functions to converts strz to integer
---
Modified: src/core/ut.h
---
Diff: https://github.com/kamailio/kamailio/commit/b36da1dca71036ea3aa52675d3166317... Patch: https://github.com/kamailio/kamailio/commit/b36da1dca71036ea3aa52675d3166317...
---
diff --git a/src/core/ut.h b/src/core/ut.h index 8b64070947..a841449164 100644 --- a/src/core/ut.h +++ b/src/core/ut.h @@ -689,6 +689,62 @@ static inline int str2sint(str* _s, int* _r) }
+/* + * Convert a str into integer + */ +static inline int strz2int(char* _s, unsigned int* _r) +{ + int i; + + if (_r == NULL) return -1; + *_r = 0; + if (_s == NULL) return -1; + + for(i = 0; _s[i] != '\0'; i++) { + if ((_s[i] >= '0') && (_s[i] <= '9')) { + *_r *= 10; + *_r += _s[i] - '0'; + } else { + return -1; + } + } + + return 0; +} + +/* + * Convert an str to signed integer + */ +static inline int strz2sint(char* _s, int* _r) +{ + int i; + int sign; + + if (_r == NULL) return -1; + *_r = 0; + if (_s == NULL) return -1; + + sign = 1; + i = 0; + if (_s[0] == '+') { + i++; + } else if (_s[0] == '-') { + sign = -1; + i++; + } + for(; _s[i] != '\0'; i++) { + if ((_s[i] >= '0') && (_s[i] <= '9')) { + *_r *= 10; + *_r += _s[i] - '0'; + } else { + return -1; + } + } + *_r *= sign; + + return 0; +} +
/** * \brief Make a copy of a str structure to a str using shm_malloc