4 This file is part of avahi.
6 avahi is free software; you can redistribute it and/or modify it
7 under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 avahi is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
13 or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
14 Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with avahi; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
35 #include <avahi-common/malloc.h>
40 static GDBM_FILE gdbm_file = NULL;
43 static DBM *dbm_file = NULL;
45 static char *buffer = NULL;
47 static int init(void) {
53 if (!(gdbm_file = gdbm_open((char*) DATABASE_FILE, 0, GDBM_READER, 0, NULL)))
60 if (!(dbm_file = dbm_open((char*) DATABASE_FILE, O_RDONLY, 0)))
67 const char* stdb_lookup(const char *name) {
77 if ((loc = setlocale(LC_MESSAGES, NULL))) {
80 snprintf(k, sizeof(k), "%s[%s]", name, loc);
82 key.dsize = strlen(k);
84 data = gdbm_fetch(gdbm_file, key);
87 data = dbm_fetch(dbm_file, key);
92 snprintf(l, sizeof(l), "%s", loc);
94 if ((e = strchr(l, '@'))) {
96 snprintf(k, sizeof(k), "%s[%s]", name, l);
98 key.dsize = strlen(k);
100 data = gdbm_fetch(gdbm_file, key);
103 data = dbm_fetch(dbm_file, key);
108 if ((e = strchr(l, '_'))) {
110 snprintf(k, sizeof(k), "%s[%s]", name, l);
112 key.dsize = strlen(k);
114 data = gdbm_fetch(gdbm_file, key);
117 data = dbm_fetch(dbm_file, key);
125 key.dptr = (char*) name;
126 key.dsize = strlen(name);
128 data = gdbm_fetch(gdbm_file, key);
131 data = dbm_fetch(dbm_file, key);
139 buffer = avahi_strndup(data.dptr, data.dsize);
149 void stdb_shutdown(void) {
152 gdbm_close(gdbm_file);