From e9f820d17f695e5bf865ee1ed23bd2bb15eaa947 Mon Sep 17 00:00:00 2001 From: pancake Date: Mon, 12 May 2014 10:44:19 +0200 Subject: [PATCH] Bump sdb --- libr/include/sdb/sdb.h | 4 ++-- shlr/sdb/src/disk.c | 6 ++++-- shlr/sdb/src/query.c | 12 +++++++++--- shlr/sdb/src/sdb.c | 4 ++-- shlr/sdb/src/sdb.h | 4 ++-- 5 files changed, 19 insertions(+), 11 deletions(-) diff --git a/libr/include/sdb/sdb.h b/libr/include/sdb/sdb.h index 2929f120e9..edeaa790b0 100644 --- a/libr/include/sdb/sdb.h +++ b/libr/include/sdb/sdb.h @@ -107,7 +107,7 @@ int sdb_foreach (Sdb* s, SdbForeachCallback cb, void *user); int sdb_disk_create (Sdb* s); int sdb_disk_insert (Sdb* s, const char *key, const char *val); int sdb_disk_finish (Sdb* s); -void sdb_disk_unlink (Sdb* s); +int sdb_disk_unlink (Sdb* s); /* iterate */ void sdb_dump_begin (Sdb* s); @@ -127,7 +127,7 @@ ut64 sdb_num_dec (Sdb* s, const char *key, ut64 n, ut32 cas); int sdb_lock(const char *s); const char *sdb_lockfile(const char *f); void sdb_unlock(const char *s); -SDB_API void sdb_unlink (Sdb* s); +SDB_API int sdb_unlink (Sdb* s); SDB_API int sdb_lock_wait(const char *s UNUSED); /* expiration */ diff --git a/shlr/sdb/src/disk.c b/shlr/sdb/src/disk.c index 78b52450a3..c9686affc0 100644 --- a/shlr/sdb/src/disk.c +++ b/shlr/sdb/src/disk.c @@ -81,7 +81,9 @@ SDB_API int sdb_disk_finish (Sdb* s) { return ret; } -SDB_API void sdb_disk_unlink (Sdb *s) { +SDB_API int sdb_disk_unlink (Sdb *s) { if (s->dir && *(s->dir)) - unlink (s->dir); + if (unlink (s->dir) != -1) + return 1; + return 0; } diff --git a/shlr/sdb/src/query.c b/shlr/sdb/src/query.c index 6c3398d401..bec03bd6a4 100644 --- a/shlr/sdb/src/query.c +++ b/shlr/sdb/src/query.c @@ -121,6 +121,7 @@ repeat: } eq = strchr (p, '='); if (eq) { + d = 1; *eq++ = 0; if (*eq=='$') { next = strchr (eq+1, ';'); @@ -129,7 +130,10 @@ repeat: if (next) *next = ';'; is_ref = 1; // protect readonly buffer from being processed } else val = eq; - } else val = NULL; + } else { + val = NULL; + d = 0; + } if (!is_ref) { next = strchr (val?val:cmd, ';'); //val?val:cmd, ';'); } @@ -545,13 +549,15 @@ fail: } SDB_API int sdb_query (Sdb *s, const char *cmd) { - char buf[1024], *out = sdb_querys (s, buf, sizeof (buf), cmd); + char buf[1024], *out; + int must_save = ((*cmd=='~') || strchr (cmd, '=')); + out = sdb_querys (s, buf, sizeof (buf), cmd); if (out) { if (*out) puts (out); if (out != buf) free (out); } - return ((*cmd=='~')||strchr (cmd, '='))? 1: 0; + return must_save; } SDB_API int sdb_query_lines (Sdb *s, const char *cmd) { diff --git a/shlr/sdb/src/sdb.c b/shlr/sdb/src/sdb.c index 96bb6fc49b..b20c0039f3 100644 --- a/shlr/sdb/src/sdb.c +++ b/shlr/sdb/src/sdb.c @@ -629,11 +629,11 @@ SDB_API void sdb_config(Sdb *s, int options) { } } -SDB_API void sdb_unlink (Sdb* s) { +SDB_API int sdb_unlink (Sdb* s) { // nullify Sdb sdb_fini (s, 1); // remove from disk - sdb_disk_unlink (s); + return sdb_disk_unlink (s); } SDB_API void sdb_drain(Sdb *s, Sdb *f) { diff --git a/shlr/sdb/src/sdb.h b/shlr/sdb/src/sdb.h index 2929f120e9..edeaa790b0 100644 --- a/shlr/sdb/src/sdb.h +++ b/shlr/sdb/src/sdb.h @@ -107,7 +107,7 @@ int sdb_foreach (Sdb* s, SdbForeachCallback cb, void *user); int sdb_disk_create (Sdb* s); int sdb_disk_insert (Sdb* s, const char *key, const char *val); int sdb_disk_finish (Sdb* s); -void sdb_disk_unlink (Sdb* s); +int sdb_disk_unlink (Sdb* s); /* iterate */ void sdb_dump_begin (Sdb* s); @@ -127,7 +127,7 @@ ut64 sdb_num_dec (Sdb* s, const char *key, ut64 n, ut32 cas); int sdb_lock(const char *s); const char *sdb_lockfile(const char *f); void sdb_unlock(const char *s); -SDB_API void sdb_unlink (Sdb* s); +SDB_API int sdb_unlink (Sdb* s); SDB_API int sdb_lock_wait(const char *s UNUSED); /* expiration */