summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/basic/user-util.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/src/basic/user-util.c b/src/basic/user-util.c
index 637391f4a7..ebeac99d31 100644
--- a/src/basic/user-util.c
+++ b/src/basic/user-util.c
@@ -31,40 +31,35 @@
bool uid_is_valid(uid_t uid) {
/* Some libc APIs use UID_INVALID as special placeholder */
- if (uid == (uid_t) 0xFFFFFFFF)
+ if (uid == (uid_t) UINT32_C(0xFFFFFFFF))
return false;
/* A long time ago UIDs where 16bit, hence explicitly avoid the 16bit -1 too */
- if (uid == (uid_t) 0xFFFF)
+ if (uid == (uid_t) UINT32_C(0xFFFF))
return false;
return true;
}
-int parse_uid(const char *s, uid_t* ret_uid) {
- unsigned long ul = 0;
- uid_t uid;
+int parse_uid(const char *s, uid_t *ret) {
+ uint32_t uid = 0;
int r;
assert(s);
- r = safe_atolu(s, &ul);
+ assert_cc(sizeof(uid_t) == sizeof(uint32_t));
+ r = safe_atou32(s, &uid);
if (r < 0)
return r;
- uid = (uid_t) ul;
-
- if ((unsigned long) uid != ul)
- return -ERANGE;
-
if (!uid_is_valid(uid))
return -ENXIO; /* we return ENXIO instead of EINVAL
* here, to make it easy to distuingish
* invalid numeric uids invalid
* strings. */
- if (ret_uid)
- *ret_uid = uid;
+ if (ret)
+ *ret = uid;
return 0;
}