diff options
author | Lennart Poettering <lennart@poettering.net> | 2010-06-17 22:50:35 +0200 |
---|---|---|
committer | Lennart Poettering <lennart@poettering.net> | 2010-06-17 22:50:35 +0200 |
commit | 3ba686c107b2b33e706f59432584875a4152d19a (patch) | |
tree | f23e1af7167346926e226439f1cf791d5f8b93ff /src/util.c | |
parent | 4a2a8b5a82325494f5daf4c66c23fdb4f906c9e6 (diff) |
util: implement parse_pid() function
Diffstat (limited to 'src/util.c')
-rw-r--r-- | src/util.c | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/util.c b/src/util.c index ed0991a68b..8f70c0f28a 100644 --- a/src/util.c +++ b/src/util.c @@ -241,6 +241,29 @@ int parse_boolean(const char *v) { return -EINVAL; } +int parse_pid(const char *s, pid_t* ret_pid) { + unsigned long ul; + pid_t pid; + int r; + + assert(s); + assert(ret_pid); + + if ((r = safe_atolu(s, &ul)) < 0) + return r; + + pid = (pid_t) ul; + + if ((unsigned long) pid != ul) + return -ERANGE; + + if (pid <= 0) + return -ERANGE; + + *ret_pid = pid; + return 0; +} + int safe_atou(const char *s, unsigned *ret_u) { char *x = NULL; unsigned long l; |