MCPcopy Create free account
hub / github.com/corosync/corosync / util_strtonum

Function util_strtonum

tools/util.c:10–35  ·  view source on GitHub ↗

* Safer wrapper of strtoll. Return 0 on success, otherwise -1. * Idea from corosync-qdevice project */

Source from the content-addressed store, hash-verified

8 * Idea from corosync-qdevice project
9 */
10int
11util_strtonum(const char *str, long long int min_val, long long int max_val,
12 long long int *res)
13{
14 long long int tmp_ll;
15 char *ep;
16
17 if (min_val > max_val) {
18 return (-1);
19 }
20
21 errno = 0;
22
23 tmp_ll = strtoll(str, &ep, 10);
24 if (ep == str || *ep != '\0' || errno != 0) {
25 return (-1);
26 }
27
28 if (tmp_ll < min_val || tmp_ll > max_val) {
29 return (-1);
30 }
31
32 *res = tmp_ll;
33
34 return (0);
35}

Callers 2

mainFunction · 0.85
mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected