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

Function fiboptlist_range

tools/route/route.c:327–375  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

325}
326
327static int
328fiboptlist_range(const char *arg, struct fibl_head_t *flh)
329{
330 struct fibl *fl;
331 char *str0, *str, *token, *endptr;
332 int fib[2], i, error;
333
334 str0 = str = strdup(arg);
335 error = 0;
336 i = 0;
337 while ((token = strsep(&str, "-")) != NULL) {
338 switch (i) {
339 case 0:
340 case 1:
341 errno = 0;
342 fib[i] = strtol(token, &endptr, 0);
343 if (errno == 0) {
344 if (*endptr != '\0' ||
345 fib[i] < 0 ||
346 (numfibs != -1 && fib[i] > numfibs - 1))
347 errno = EINVAL;
348 }
349 if (errno)
350 error = 1;
351 break;
352 default:
353 error = 1;
354 }
355 if (error)
356 goto fiboptlist_range_ret;
357 i++;
358 }
359 if (fib[0] >= fib[1]) {
360 error = 1;
361 goto fiboptlist_range_ret;
362 }
363 for (i = fib[0]; i <= fib[1]; i++) {
364 fl = calloc(1, sizeof(*fl));
365 if (fl == NULL) {
366 error = 1;
367 goto fiboptlist_range_ret;
368 }
369 fl->fl_num = i;
370 TAILQ_INSERT_TAIL(flh, fl, fl_next);
371 }
372fiboptlist_range_ret:
373 free(str0);
374 return (error);
375}
376
377#define ALLSTRLEN 64
378static int

Callers 1

fiboptlist_csvFunction · 0.85

Calls 5

strdupFunction · 0.85
strsepFunction · 0.85
strtolFunction · 0.85
callocFunction · 0.85
freeFunction · 0.50

Tested by

no test coverage detected