aboutsummaryrefslogtreecommitdiffstats
path: root/ll-database-binding
diff options
context:
space:
mode:
authorJosé Bollo <jose.bollo@iot.bzh>2017-10-25 11:06:30 +0200
committerJosé Bollo <jose.bollo@iot.bzh>2017-10-25 11:06:30 +0200
commitb18e88a7e419feb6ef6dab7df2ecf4d3c181b61b (patch)
tree832c6538905e5714f19e93da24a608fd474ca851 /ll-database-binding
parent9df5caf58cb50dedf77d2bfa9cd1c4ecaa6151d6 (diff)
database: include null and improve readability
Change-Id: Iecf336beb8c5187fd4ed86f7785cd6bf1170cf19 Signed-off-by: José Bollo <jose.bollo@iot.bzh>
Diffstat (limited to 'll-database-binding')
-rw-r--r--ll-database-binding/src/ll-database-binding.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/ll-database-binding/src/ll-database-binding.c b/ll-database-binding/src/ll-database-binding.c
index 524327f..bd6a2a0 100644
--- a/ll-database-binding/src/ll-database-binding.c
+++ b/ll-database-binding/src/ll-database-binding.c
@@ -104,13 +104,15 @@ static int ll_database_binding_init()
AFB_INFO("opening database %s", path);
- if ((ret = db_create(&database, NULL, 0)) != 0)
+ ret = db_create(&database, NULL, 0);
+ if (ret != 0)
{
AFB_ERROR("Failed to create database: %s.", db_strerror(ret));
return -1;
}
- if ((ret = database->open(database, NULL, path, NULL, DB_BTREE, DB_CREATE, 0664)) != 0)
+ ret = database->open(database, NULL, path, NULL, DB_BTREE, DB_CREATE, 0664);
+ if (ret != 0)
{
AFB_ERROR("Failed to open the '%s' database: %s.", path, db_strerror(ret));
database->close(database, 0);
@@ -211,7 +213,7 @@ static void put(struct afb_req req, int replace)
AFB_INFO("put: key=%s, value=%s", (char*)key.data, value);
data.data = (void*)value;
- data.size = (uint32_t)strlen(value);
+ data.size = (uint32_t)strlen(value) + 1; /* includes the tailing null */
ret = database->put(database, NULL, &key, &data, replace ? 0 : DB_NOOVERWRITE);
if (ret == 0)
@@ -273,7 +275,8 @@ static void verb_read(struct afb_req req)
data.ulen = 4096;
data.flags = DB_DBT_USERMEM;
- if ((ret = database->get(database, NULL, &key, &data, 0)) == 0)
+ ret = database->get(database, NULL, &key, &data, 0);
+ if (ret == 0)
{
result = json_object_new_object();
val = json_tokener_parse((char*)data.data);