diff options
author | Lennart Poettering <lennart@poettering.net> | 2014-11-14 13:11:10 +0100 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2014-11-14 13:18:51 +0100 |
commit | 781fa93815fafd02b5287ef5781b92ef7b99973b (patch) | |
tree | 5ff4471b65649d3b98fe27fd98baab0d8e7830e4 /src/shared/util.c | |
parent | 8022212b3b8e553fd83b87575f3e730e56852d5d (diff) |
busctl: add new "call" command to invoke methods on a service
Diffstat (limited to 'src/shared/util.c')
-rw-r--r-- | src/shared/util.c | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/shared/util.c b/src/shared/util.c index 2f4fa237dd..eeced4769a 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -363,6 +363,46 @@ int safe_atou8(const char *s, uint8_t *ret) { return 0; } +int safe_atou16(const char *s, uint16_t *ret) { + char *x = NULL; + unsigned long l; + + assert(s); + assert(ret); + + errno = 0; + l = strtoul(s, &x, 0); + + if (!x || x == s || *x || errno) + return errno > 0 ? -errno : -EINVAL; + + if ((unsigned long) (uint16_t) l != l) + return -ERANGE; + + *ret = (uint16_t) l; + return 0; +} + +int safe_atoi16(const char *s, int16_t *ret) { + char *x = NULL; + long l; + + assert(s); + assert(ret); + + errno = 0; + l = strtol(s, &x, 0); + + if (!x || x == s || *x || errno) + return errno > 0 ? -errno : -EINVAL; + + if ((long) (int16_t) l != l) + return -ERANGE; + + *ret = (int16_t) l; + return 0; +} + int safe_atollu(const char *s, long long unsigned *ret_llu) { char *x = NULL; unsigned long long l; |