MCPcopy Create free account
hub / github.com/F-Stack/f-stack / time_to_us

Function time_to_us

tools/ipfw/dummynet.c:187–220  ·  view source on GitHub ↗

* returns -1 if s is not a valid time, otherwise, return time in us */

Source from the content-addressed store, hash-verified

185 * returns -1 if s is not a valid time, otherwise, return time in us
186 */
187static long
188time_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 */

Callers 1

process_extra_parmsFunction · 0.85

Calls 3

isdigitFunction · 0.85
strncpyFunction · 0.85
strcasecmpFunction · 0.85

Tested by

no test coverage detected