New function mu_dbm_stat(): retrieve struct stat for a database file
(or its *.pag part for ndbm/gdbm).
Showing
1 changed file
with
87 additions
and
17 deletions
... | @@ -71,7 +71,18 @@ mu_check_perm (char *name, int mode) | ... | @@ -71,7 +71,18 @@ mu_check_perm (char *name, int mode) |
71 | #define DB_SUFFIX ".db" | 71 | #define DB_SUFFIX ".db" |
72 | 72 | ||
73 | int | 73 | int |
74 | mu_dbm_open(char *name, DBM_FILE *db, int flags, int mode) | 74 | mu_dbm_stat (char *name, struct stat *sb) |
75 | { | ||
76 | int rc; | ||
77 | char *pfname = xmalloc (strlen (name) + sizeof DB_SUFFIX); | ||
78 | strcat (strcpy (pfname, name), DB_SUFFIX); | ||
79 | rc = stat (pfname, sb); | ||
80 | free (pfname); | ||
81 | return rc; | ||
82 | } | ||
83 | |||
84 | int | ||
85 | mu_dbm_open (char *name, DBM_FILE *db, int flags, int mode) | ||
75 | { | 86 | { |
76 | int f; | 87 | int f; |
77 | char *pfname; | 88 | char *pfname; |
... | @@ -106,21 +117,27 @@ mu_dbm_open(char *name, DBM_FILE *db, int flags, int mode) | ... | @@ -106,21 +117,27 @@ mu_dbm_open(char *name, DBM_FILE *db, int flags, int mode) |
106 | } | 117 | } |
107 | 118 | ||
108 | int | 119 | int |
109 | mu_dbm_close(DBM_FILE db) | 120 | mu_dbm_close (DBM_FILE db) |
110 | { | 121 | { |
111 | gdbm_close(db); | 122 | gdbm_close(db); |
112 | return 0; | 123 | return 0; |
113 | } | 124 | } |
114 | 125 | ||
115 | int | 126 | int |
116 | mu_dbm_fetch(DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret) | 127 | mu_dbm_fetch (DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret) |
117 | { | 128 | { |
118 | *ret = gdbm_fetch(db, key); | 129 | *ret = gdbm_fetch(db, key); |
119 | return ret->dptr == NULL; | 130 | return ret->dptr == NULL; |
120 | } | 131 | } |
121 | 132 | ||
122 | int | 133 | int |
123 | mu_dbm_insert(DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace) | 134 | mu_dbm_delete (DBM_FILE db, DBM_DATUM key) |
135 | { | ||
136 | return gdbm_delete (db, key); | ||
137 | } | ||
138 | |||
139 | int | ||
140 | mu_dbm_insert (DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace) | ||
124 | { | 141 | { |
125 | return gdbm_store(db, key, contents, | 142 | return gdbm_store(db, key, contents, |
126 | replace ? GDBM_REPLACE : GDBM_INSERT); | 143 | replace ? GDBM_REPLACE : GDBM_INSERT); |
... | @@ -143,7 +160,18 @@ mu_dbm_nextkey (DBM_FILE db, DBM_DATUM key) | ... | @@ -143,7 +160,18 @@ mu_dbm_nextkey (DBM_FILE db, DBM_DATUM key) |
143 | #define DB_SUFFIX ".db" | 160 | #define DB_SUFFIX ".db" |
144 | 161 | ||
145 | int | 162 | int |
146 | mu_dbm_open(char *name, DBM_FILE *dbm, int flags, int mode) | 163 | mu_dbm_stat (char *name, struct stat *sb) |
164 | { | ||
165 | int rc; | ||
166 | char *pfname = xmalloc (strlen (name) + sizeof DB_SUFFIX); | ||
167 | strcat (strcpy (pfname, name), DB_SUFFIX); | ||
168 | rc = stat (pfname, sb); | ||
169 | free (pfname); | ||
170 | return rc; | ||
171 | } | ||
172 | |||
173 | int | ||
174 | mu_dbm_open (char *name, DBM_FILE *dbm, int flags, int mode) | ||
147 | { | 175 | { |
148 | int f, rc; | 176 | int f, rc; |
149 | DB *db; | 177 | DB *db; |
... | @@ -192,7 +220,7 @@ mu_dbm_open(char *name, DBM_FILE *dbm, int flags, int mode) | ... | @@ -192,7 +220,7 @@ mu_dbm_open(char *name, DBM_FILE *dbm, int flags, int mode) |
192 | } | 220 | } |
193 | 221 | ||
194 | int | 222 | int |
195 | mu_dbm_close(DBM_FILE db) | 223 | mu_dbm_close (DBM_FILE db) |
196 | { | 224 | { |
197 | db->db->close (db->db, 0); | 225 | db->db->close (db->db, 0); |
198 | free (db); | 226 | free (db); |
... | @@ -200,13 +228,19 @@ mu_dbm_close(DBM_FILE db) | ... | @@ -200,13 +228,19 @@ mu_dbm_close(DBM_FILE db) |
200 | } | 228 | } |
201 | 229 | ||
202 | int | 230 | int |
203 | mu_dbm_fetch(DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret) | 231 | mu_dbm_fetch (DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret) |
204 | { | 232 | { |
205 | return db->db->get (db->db, NULL, &key, ret, 0); | 233 | return db->db->get (db->db, NULL, &key, ret, 0); |
206 | } | 234 | } |
207 | 235 | ||
208 | int | 236 | int |
209 | mu_dbm_insert(DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace) | 237 | mu_dbm_delete (DBM_FILE db, DBM_DATUM key) |
238 | { | ||
239 | return db->db->del (db->db, NULL, &key, 0); | ||
240 | } | ||
241 | |||
242 | int | ||
243 | mu_dbm_insert (DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace) | ||
210 | { | 244 | { |
211 | /*FIXME: replace unused*/ | 245 | /*FIXME: replace unused*/ |
212 | return db->db->put (db->db, NULL, &key, &contents, 0); | 246 | return db->db->put (db->db, NULL, &key, &contents, 0); |
... | @@ -265,10 +299,21 @@ mu_dbm_nextkey (DBM_FILE db, DBM_DATUM pkey /*unused*/) | ... | @@ -265,10 +299,21 @@ mu_dbm_nextkey (DBM_FILE db, DBM_DATUM pkey /*unused*/) |
265 | 299 | ||
266 | #elif defined(WITH_NDBM) | 300 | #elif defined(WITH_NDBM) |
267 | 301 | ||
268 | #define DB_SUFFIX ".db" | 302 | #define DB_SUFFIX ".pag" |
269 | 303 | ||
270 | int | 304 | int |
271 | mu_dbm_open(char *name, DBM_FILE *db, int flags, int mode) | 305 | mu_dbm_stat (char *name, struct stat *sb) |
306 | { | ||
307 | int rc; | ||
308 | char *pfname = xmalloc (strlen (name) + sizeof DB_SUFFIX); | ||
309 | strcat (strcpy (pfname, name), DB_SUFFIX); | ||
310 | rc = stat (pfname, sb); | ||
311 | free (pfname); | ||
312 | return rc; | ||
313 | } | ||
314 | |||
315 | int | ||
316 | mu_dbm_open (char *name, DBM_FILE *db, int flags, int mode) | ||
272 | { | 317 | { |
273 | int f; | 318 | int f; |
274 | 319 | ||
... | @@ -302,21 +347,27 @@ mu_dbm_open(char *name, DBM_FILE *db, int flags, int mode) | ... | @@ -302,21 +347,27 @@ mu_dbm_open(char *name, DBM_FILE *db, int flags, int mode) |
302 | } | 347 | } |
303 | 348 | ||
304 | int | 349 | int |
305 | mu_dbm_close(DBM_FILE db) | 350 | mu_dbm_close (DBM_FILE db) |
306 | { | 351 | { |
307 | dbm_close(db); | 352 | dbm_close(db); |
308 | return 0; | 353 | return 0; |
309 | } | 354 | } |
310 | 355 | ||
311 | int | 356 | int |
312 | mu_dbm_fetch(DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret) | 357 | mu_dbm_fetch (DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret) |
313 | { | 358 | { |
314 | *ret = dbm_fetch(db, key); | 359 | *ret = dbm_fetch(db, key); |
315 | return ret->dptr == NULL; | 360 | return ret->dptr == NULL; |
316 | } | 361 | } |
317 | 362 | ||
318 | int | 363 | int |
319 | mu_dbm_insert(DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace) | 364 | mu_dbm_delete (DBM_FILE db, DBM_DATUM key) |
365 | { | ||
366 | return dbm_delete (db, key); | ||
367 | } | ||
368 | |||
369 | int | ||
370 | mu_dbm_insert (DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace) | ||
320 | { | 371 | { |
321 | return dbm_store(db, key, contents, replace ? DBM_REPLACE : DBM_INSERT); | 372 | return dbm_store(db, key, contents, replace ? DBM_REPLACE : DBM_INSERT); |
322 | } | 373 | } |
... | @@ -335,9 +386,22 @@ mu_dbm_nextkey (DBM_FILE db, DBM_DATUM key) | ... | @@ -335,9 +386,22 @@ mu_dbm_nextkey (DBM_FILE db, DBM_DATUM key) |
335 | 386 | ||
336 | #elif defined(WITH_OLD_DBM) | 387 | #elif defined(WITH_OLD_DBM) |
337 | 388 | ||
389 | #define DB_SUFFIX ".pag" | ||
390 | |||
391 | int | ||
392 | mu_dbm_stat (char *name, struct stat *sb) | ||
393 | { | ||
394 | int rc; | ||
395 | char *pfname = xmalloc (strlen (name) + sizeof DB_SUFFIX); | ||
396 | strcat (strcpy (pfname, name), DB_SUFFIX); | ||
397 | rc = stat (pfname, sb); | ||
398 | free (pfname); | ||
399 | return rc; | ||
400 | } | ||
401 | |||
338 | /*ARGSUSED*/ | 402 | /*ARGSUSED*/ |
339 | int | 403 | int |
340 | mu_dbm_open(char *name, DBM_FILE *db, int flags, int mode) | 404 | mu_dbm_open (char *name, DBM_FILE *db, int flags, int mode) |
341 | { | 405 | { |
342 | int f; | 406 | int f; |
343 | 407 | ||
... | @@ -383,7 +447,7 @@ mu_dbm_open(char *name, DBM_FILE *db, int flags, int mode) | ... | @@ -383,7 +447,7 @@ mu_dbm_open(char *name, DBM_FILE *db, int flags, int mode) |
383 | 447 | ||
384 | /*ARGSUSED*/ | 448 | /*ARGSUSED*/ |
385 | int | 449 | int |
386 | mu_dbm_close(DBM_FILE db) | 450 | mu_dbm_close (DBM_FILE db) |
387 | { | 451 | { |
388 | dbmclose(); | 452 | dbmclose(); |
389 | return 0; | 453 | return 0; |
... | @@ -391,14 +455,20 @@ mu_dbm_close(DBM_FILE db) | ... | @@ -391,14 +455,20 @@ mu_dbm_close(DBM_FILE db) |
391 | 455 | ||
392 | /*ARGSUSED*/ | 456 | /*ARGSUSED*/ |
393 | int | 457 | int |
394 | mu_dbm_fetch(DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret) | 458 | mu_dbm_fetch (DBM_FILE db, DBM_DATUM key, DBM_DATUM *ret) |
395 | { | 459 | { |
396 | *ret = fetch(key); | 460 | *ret = fetch(key); |
397 | return ret->dptr == NULL; | 461 | return ret->dptr == NULL; |
398 | } | 462 | } |
399 | 463 | ||
400 | int | 464 | int |
401 | mu_dbm_insert(DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace) | 465 | mu_dbm_delete (DBM_FILE db, DBM_DATUM key) |
466 | { | ||
467 | return delete (key); | ||
468 | } | ||
469 | |||
470 | int | ||
471 | mu_dbm_insert (DBM_FILE db, DBM_DATUM key, DBM_DATUM contents, int replace) | ||
402 | { | 472 | { |
403 | return store(key, contents); | 473 | return store(key, contents); |
404 | } | 474 | } | ... | ... |
-
Please register or sign in to post a comment