Blob Blame History Raw
From 91c41b25f3d2e5a6074d1dd73c3355f9159d2cae Mon Sep 17 00:00:00 2001
From: Sumit Bose <sbose@redhat.com>
Date: Tue, 10 Dec 2013 10:14:02 +0100
Subject: [PATCH 41/41] Add sysdb_attrs_get_int32_t

---
 src/db/sysdb.c | 26 ++++++++++++++++++++++++++
 src/db/sysdb.h |  2 ++
 2 files changed, 28 insertions(+)

diff --git a/src/db/sysdb.c b/src/db/sysdb.c
index 2a4be58008fc1164765db26aaba3886071448d30..0e07ed60858298a1ac85d06146ccb98c5899a705 100644
--- a/src/db/sysdb.c
+++ b/src/db/sysdb.c
@@ -366,6 +366,32 @@ int sysdb_attrs_get_string(struct sysdb_attrs *attrs, const char *name,
     return EOK;
 }
 
+int sysdb_attrs_get_int32_t(struct sysdb_attrs *attrs, const char *name,
+                             int32_t *value)
+{
+    struct ldb_message_element *el;
+    int ret;
+    char *endptr;
+    int32_t val;
+
+    ret = sysdb_attrs_get_el_ext(attrs, name, false, &el);
+    if (ret) {
+        return ret;
+    }
+
+    if (el->num_values != 1) {
+        return ERANGE;
+    }
+
+    errno = 0;
+    val = strtoint32((const char *) el->values[0].data, &endptr, 10);
+    if (errno != 0) return errno;
+    if (*endptr) return EINVAL;
+
+    *value = val;
+    return EOK;
+}
+
 int sysdb_attrs_get_uint32_t(struct sysdb_attrs *attrs, const char *name,
                              uint32_t *value)
 {
diff --git a/src/db/sysdb.h b/src/db/sysdb.h
index 9bcd7be0960fcfa390fb9150594ea84880a14eea..255a135f0cad788e4c952b86fe24ca10f5e63732 100644
--- a/src/db/sysdb.h
+++ b/src/db/sysdb.h
@@ -294,6 +294,8 @@ errno_t sysdb_attrs_get_bool(struct sysdb_attrs *attrs, const char *name,
                              bool *value);
 int sysdb_attrs_get_uint16_t(struct sysdb_attrs *attrs, const char *name,
                              uint16_t *value);
+int sysdb_attrs_get_int32_t(struct sysdb_attrs *attrs, const char *name,
+                             int32_t *value);
 int sysdb_attrs_get_uint32_t(struct sysdb_attrs *attrs, const char *name,
                              uint32_t *value);
 
-- 
1.8.4.2