* returns -1 if s is not a valid time, otherwise, return time in us */
| 185 | * returns -1 if s is not a valid time, otherwise, return time in us |
| 186 | */ |
| 187 | static long |
| 188 | time_to_us(const char *s) |
| 189 | { |
| 190 | int i, dots = 0; |
| 191 | int len = strlen(s); |
| 192 | char strt[16]="", stru[16]=""; |
| 193 | |
| 194 | if (len>15) |
| 195 | return -1; |
| 196 | for (i = 0; i<len && (isdigit(s[i]) || s[i]=='.') ; i++) |
| 197 | if (s[i]=='.') { |
| 198 | if (dots) |
| 199 | return -1; |
| 200 | else |
| 201 | dots++; |
| 202 | } |
| 203 | |
| 204 | if (!i) |
| 205 | return -1; |
| 206 | strncpy(strt, s, i); |
| 207 | if (i<len) |
| 208 | strcpy(stru, s+i); |
| 209 | else |
| 210 | strcpy(stru, "ms"); |
| 211 | |
| 212 | if (!strcasecmp(stru, "us")) |
| 213 | return atol(strt); |
| 214 | if (!strcasecmp(stru, "ms")) |
| 215 | return (strtod(strt, NULL) * 1000); |
| 216 | if (!strcasecmp(stru, "s")) |
| 217 | return (strtod(strt, NULL)*1000000); |
| 218 | |
| 219 | return -1; |
| 220 | } |
| 221 | |
| 222 | |
| 223 | /* Get AQM or scheduler extra parameters */ |
no test coverage detected