char *p;
long l = strtol(str, &p, 0);
if (p == str)
- return -1;
+ return -NLE_INVAL;
if (*p) {
if (!strcasecmp(p, "kb") || !strcasecmp(p, "k"))
else if (!strcasecmp(p, "bit"))
l /= 8;
else if (strcasecmp(p, "b") != 0)
- return -1;
+ return -NLE_INVAL;
}
return l;
double d = strtod(str, &p);
if (p == str)
- return -1;
+ return -NLE_INVAL;
if (d > 1.0)
d /= 100.0f;
if (d > 1.0f || d < 0.0f)
- return -1;
+ return -NLE_RANGE;
if (*p && strcmp(p, "%") != 0)
- return -1;
+ return -NLE_INVAL;
return rint(d * NL_PROB_MAX);
}
char *p;
long l = strtol(str, &p, 0);
if (p == str)
- return -1;
+ return -NLE_INVAL;
if (*p) {
if (!strcasecmp(p, "min") == 0 || !strcasecmp(p, "m"))
else if (!strcasecmp(p, "day") || !strcasecmp(p, "d"))
l *= 60*60*24;
else if (strcasecmp(p, "s") != 0)
- return -1;
+ return -NLE_INVAL;
}
return l;
l = strtoul(name, &end, 0);
if (l == ULONG_MAX || *end != '\0')
- return -1;
+ return -NLE_OBJ_NOTFOUND;
return (int) l;
}
int i;
if (*buf == '\0')
- return -1;
+ return -NLE_INVAL;
for (i = 0; i < tbl_len; i++)
if (!strcasecmp(tbl[i].a, buf))
l = strtoul(buf, &end, 0);
if (l == ULONG_MAX || *end != '\0')
- return -1;
+ return -NLE_OBJ_NOTFOUND;
return (int) l;
}
char *end;
if (*buf == '\0')
- return -1;
+ return -NLE_INVAL;
nl_list_for_each_entry(tl, head, list) {
if (!strcasecmp(tl->a, buf))
l = strtoul(buf, &end, 0);
if (l == ULONG_MAX || *end != '\0')
- return -1;
+ return -NLE_OBJ_NOTFOUND;
return (int) l;
}