X-Git-Url: http://git.meshlink.io/?a=blobdiff_plain;f=avahi-utils%2Fstdb.c;h=388bf6b508860a0dd597e4405fd775c475ff637b;hb=1d4f819072e901518309aff781f9f1e7272dca87;hp=53be7766cb5c7959d5ca7327ba7bd756dff0e382;hpb=48f053dc87279e2e3cad561db5b744cbcbf32387;p=catta diff --git a/avahi-utils/stdb.c b/avahi-utils/stdb.c index 53be776..388bf6b 100644 --- a/avahi-utils/stdb.c +++ b/avahi-utils/stdb.c @@ -19,7 +19,14 @@ USA. ***/ +#include +#ifdef HAVE_GDBM #include +#endif +#ifdef HAVE_DBM +#include +#include +#endif #include #include #include @@ -29,16 +36,30 @@ #include "stdb.h" +#ifdef HAVE_GDBM static GDBM_FILE gdbm_file = NULL; +#endif +#ifdef HAVE_DBM +static DBM *dbm_file = NULL; +#endif static char *buffer = NULL; static int init(void) { +#ifdef HAVE_GDBM if (gdbm_file) return 0; if (!(gdbm_file = gdbm_open((char*) DATABASE_FILE, 0, GDBM_READER, 0, NULL))) return -1; +#endif +#ifdef HAVE_DBM + if (dbm_file) + return 0; + + if (!(dbm_file = dbm_open((char*) DATABASE_FILE, O_RDONLY, 0))) + return -1; +#endif return 0; } @@ -59,7 +80,12 @@ const char* stdb_lookup(const char *name) { snprintf(k, sizeof(k), "%s[%s]", name, loc); key.dptr = k; key.dsize = strlen(k); +#ifdef HAVE_GDBM data = gdbm_fetch(gdbm_file, key); +#endif +#ifdef HAVE_DBM + data = dbm_fetch(dbm_file, key); +#endif if (!data.dptr) { char l[32], *e; @@ -70,7 +96,12 @@ const char* stdb_lookup(const char *name) { snprintf(k, sizeof(k), "%s[%s]", name, l); key.dptr = k; key.dsize = strlen(k); +#ifdef HAVE_GDBM data = gdbm_fetch(gdbm_file, key); +#endif +#ifdef HAVE_DBM + data = dbm_fetch(dbm_file, key); +#endif } if (!data.dptr) { @@ -79,7 +110,12 @@ const char* stdb_lookup(const char *name) { snprintf(k, sizeof(k), "%s[%s]", name, l); key.dptr = k; key.dsize = strlen(k); +#ifdef HAVE_GDBM data = gdbm_fetch(gdbm_file, key); +#endif +#ifdef HAVE_DBM + data = dbm_fetch(dbm_file, key); +#endif } } } @@ -88,7 +124,12 @@ const char* stdb_lookup(const char *name) { if (!data.dptr) { key.dptr = (char*) name; key.dsize = strlen(name); +#ifdef HAVE_GDBM data = gdbm_fetch(gdbm_file, key); +#endif +#ifdef HAVE_DBM + data = dbm_fetch(dbm_file, key); +#endif } if (!data.dptr) @@ -106,8 +147,14 @@ fail: } void stdb_shutdown(void) { +#ifdef HAVE_GDBM if (gdbm_file) gdbm_close(gdbm_file); +#endif +#ifdef HAVE_DBM + if (dbm_file) + dbm_close(dbm_file); +#endif avahi_free(buffer); }