summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorStephen Gallagher <sgallagh@redhat.com>2012-01-18 13:22:45 -0500
committerStephen Gallagher <sgallagh@redhat.com>2012-01-23 08:31:33 -0500
commiteac695ff9189fcfcea0f233a01abf582ff685c30 (patch)
tree5b6535f8c515fec1d1a9120d05516479fc9a1071 /src/util
parent01171ddb20034578c616d0ba07f0268ab71809da (diff)
downloadsssd-eac695ff9189fcfcea0f233a01abf582ff685c30.tar.gz
sssd-eac695ff9189fcfcea0f233a01abf582ff685c30.tar.xz
sssd-eac695ff9189fcfcea0f233a01abf582ff685c30.zip
UTIL: Add strtouint16
Diffstat (limited to 'src/util')
-rw-r--r--src/util/strtonum.c18
-rw-r--r--src/util/strtonum.h2
2 files changed, 20 insertions, 0 deletions
diff --git a/src/util/strtonum.c b/src/util/strtonum.c
index bf1b21a62..22e682b4b 100644
--- a/src/util/strtonum.c
+++ b/src/util/strtonum.c
@@ -63,3 +63,21 @@ uint32_t strtouint32(const char *nptr, char **endptr, int base)
/* If errno was set by strtoll, we'll pass it back as-is */
return (uint32_t)ret;
}
+
+
+/* strtouint16 */
+uint16_t strtouint16(const char *nptr, char **endptr, int base)
+{
+ unsigned long long ret = 0;
+ errno = 0;
+ ret = strtoull(nptr, endptr, base);
+
+ if (ret > UINT16_MAX) {
+ errno = ERANGE;
+ return UINT16_MAX;
+ }
+
+ /* If errno was set by strtoll, we'll pass it back as-is */
+ return (uint16_t)ret;
+}
+
diff --git a/src/util/strtonum.h b/src/util/strtonum.h
index 450959621..d9c31e9cd 100644
--- a/src/util/strtonum.h
+++ b/src/util/strtonum.h
@@ -29,4 +29,6 @@
int32_t strtoint32(const char *nptr, char **endptr, int base);
uint32_t strtouint32(const char *nptr, char **endptr, int base);
+uint16_t strtouint16(const char *nptr, char **endptr, int base);
+
#endif /* _STRTONUM_H_ */