diff options
author | Arthur de Jong <arthur@arthurdejong.org> | 2011-08-29 20:57:37 +0000 |
---|---|---|
committer | Arthur de Jong <arthur@arthurdejong.org> | 2011-08-29 20:57:37 +0000 |
commit | ef4080e37a8827ba611246465c448b2324bada41 (patch) | |
tree | 74c268a454c2146a6dbbf719f527e917e4f251b9 /nslcd/common.c | |
parent | 8a356210e1cd0b63da5ea3b07b469db1bfe0f217 (diff) |
implement and use a strtoui() function if uid_t or gid_t is of size unsigned int (thanks Jakub Hrozek)
git-svn-id: http://arthurdejong.org/svn/nss-pam-ldapd/nss-pam-ldapd@1528 ef36b2f9-881f-0410-afb5-c4e39611909c
Diffstat (limited to 'nslcd/common.c')
-rw-r--r-- | nslcd/common.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/nslcd/common.c b/nslcd/common.c index cb94c2f..264439a 100644 --- a/nslcd/common.c +++ b/nslcd/common.c @@ -269,3 +269,20 @@ long int binsid2id(const char *binsid) return (((long int)binsid[i])&0xff)|((((long int)binsid[i+1])&0xff)<<8)| ((((long int)binsid[i+2])&0xff)<<16)|((((long int)binsid[i+3])&0xff)<<24); } + +#ifdef WANT_STRTOUI +/* provide a strtoui() implementation, similar to strtoul() but returning + an range-checked unsigned int instead */ +unsigned int strtoui(const char *nptr,char **endptr,int base) +{ + unsigned long val; + val=strtoul(nptr,endptr,base); + if (val>UINT_MAX) + { + errno=ERANGE; + return UINT_MAX; + } + /* If errno was set by strtoull, we'll pass it back as-is */ + return (unsigned int)val; +} +#endif /* WANT_STRTOUI */ |