converts a str to an u. short, returns the u. short and sets *err on * error and if err!=null */
| 182 | * error and if err!=null |
| 183 | */ |
| 184 | static inline unsigned short str2s(const char* s, unsigned int len, |
| 185 | int *err) |
| 186 | { |
| 187 | unsigned short ret; |
| 188 | int i; |
| 189 | unsigned char *limit; |
| 190 | unsigned char *str; |
| 191 | |
| 192 | /*init*/ |
| 193 | str=(unsigned char*)s; |
| 194 | ret=i=0; |
| 195 | limit=str+len; |
| 196 | |
| 197 | for(;str<limit ;str++){ |
| 198 | if ( (*str <= '9' ) && (*str >= '0') ){ |
| 199 | ret=ret*10+*str-'0'; |
| 200 | i++; |
| 201 | if (i>5) goto error_digits; |
| 202 | }else{ |
| 203 | //error unknown char |
| 204 | goto error_char; |
| 205 | } |
| 206 | } |
| 207 | if (err) *err=0; |
| 208 | return ret; |
| 209 | |
| 210 | error_digits: |
| 211 | LM_DBG("too many letters in [%.*s]\n", (int)len, s); |
| 212 | if (err) *err=1; |
| 213 | return 0; |
| 214 | error_char: |
| 215 | LM_DBG("unexpected char %c in %.*s\n", *str, (int)len, s); |
| 216 | if (err) *err=1; |
| 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | |
| 221 | static inline int btostr( char *p, unsigned char val) |
no outgoing calls
no test coverage detected