diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-08-09 11:24:56 +0000 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2011-08-09 11:24:56 +0000 |
commit | 65c1e543036bb84666c3174c58289f572b6ad948 (patch) | |
tree | dfb0e8ef1d289ad6ff8b69af177d0f4025dbff1d /compat | |
parent | 926977cf9d571e12c04162613728cabebe073c53 (diff) | |
download | gdbm-65c1e543036bb84666c3174c58289f572b6ad948.tar.gz gdbm-65c1e543036bb84666c3174c58289f572b6ad948.tar.bz2 |
Implement dbm_error and dbm_clearerr.
* compat/ndbm.h (__gdbm_error_to_ndbm): New macro
(dbm_error,dbm_clearerr): Provide prototypes instead of
the macros.
(DBM) <_dbm_errno>: New member.
* compat/dbmerr.c: New file.
* compat/Makefile.am (NDBM_CF): Add dbmerr.c
* compat/dbmdelete.c: Make sure _dbm_errno reflects the
actual error state.
* compat/dbmfetch.c: Likewise.
* compat/dbmseq.c: Likewise.
* compat/dbmstore.c: Likewise.
Diffstat (limited to 'compat')
-rw-r--r-- | compat/Makefile.am | 1 | ||||
-rw-r--r-- | compat/dbmdelete.c | 5 | ||||
-rw-r--r-- | compat/dbmerr.c | 32 | ||||
-rw-r--r-- | compat/dbmfetch.c | 2 | ||||
-rw-r--r-- | compat/dbmopen.c | 2 | ||||
-rw-r--r-- | compat/dbmseq.c | 4 | ||||
-rw-r--r-- | compat/dbmstore.c | 4 | ||||
-rw-r--r-- | compat/ndbm.h | 20 |
8 files changed, 59 insertions, 11 deletions
diff --git a/compat/Makefile.am b/compat/Makefile.am index a0ede80..e94a844 100644 --- a/compat/Makefile.am +++ b/compat/Makefile.am @@ -38,6 +38,7 @@ DBM_CF=\ NDBM_CF=\ dbmopen.c\ dbmdelete.c\ + dbmerr.c\ dbmfetch.c\ dbmstore.c\ dbmseq.c\ diff --git a/compat/dbmdelete.c b/compat/dbmdelete.c index 0f3f8a4..22e6976 100644 --- a/compat/dbmdelete.c +++ b/compat/dbmdelete.c @@ -27,5 +27,8 @@ int dbm_delete (DBM *dbm, datum key) { - return gdbm_delete (dbm->file, key); + int rc = gdbm_delete (dbm->file, key); + if (rc) + __gdbm_error_to_ndbm (dbm); + return rc; } diff --git a/compat/dbmerr.c b/compat/dbmerr.c new file mode 100644 index 0000000..aab8f31 --- /dev/null +++ b/compat/dbmerr.c @@ -0,0 +1,32 @@ +/* This file is part of GDBM, the GNU data base manager. + Copyright (C) 2011 Free Software Foundation, Inc. + + GDBM is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3, or (at your option) + any later version. + + GDBM is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GDBM. If not, see <http://www.gnu.org/licenses/>. */ + +/* Include system configuration before all else. */ +#include "autoconf.h" +#include "ndbm.h" +#include "gdbmdefs.h" + +int +dbm_error (DBM *dbf) +{ + return dbf->_dbm_errno; +} + +void +dbm_clearerr (DBM *dbf) +{ + dbf->_dbm_errno = 0; +} diff --git a/compat/dbmfetch.c b/compat/dbmfetch.c index 03a8065..edc7430 100644 --- a/compat/dbmfetch.c +++ b/compat/dbmfetch.c @@ -37,7 +37,7 @@ dbm_fetch (DBM *dbm, datum key) if (dbm->_dbm_fetch_val != NULL) free (dbm->_dbm_fetch_val); dbm->_dbm_fetch_val = ret_val.dptr; - + __gdbm_error_to_ndbm (dbm); /* Return the new value. */ return ret_val; } diff --git a/compat/dbmopen.c b/compat/dbmopen.c index 9af5922..9e66acc 100644 --- a/compat/dbmopen.c +++ b/compat/dbmopen.c @@ -219,7 +219,7 @@ dbm_open (char *file, int flags, int mode) { open_flags = GDBM_WRCREAT; } - else if ( (flags & O_TRUNC) == O_TRUNC) + else if ((flags & O_TRUNC) == O_TRUNC) { open_flags = GDBM_NEWDB; } diff --git a/compat/dbmseq.c b/compat/dbmseq.c index f98482b..57c8ab9 100644 --- a/compat/dbmseq.c +++ b/compat/dbmseq.c @@ -38,7 +38,7 @@ dbm_firstkey (DBM *dbm) if (dbm->_dbm_memory.dptr != NULL) free (dbm->_dbm_memory.dptr); dbm->_dbm_memory = ret_val; - + __gdbm_error_to_ndbm (dbm); /* Return the new value. */ return ret_val; } @@ -61,7 +61,7 @@ dbm_nextkey (DBM *dbm) if (dbm->_dbm_memory.dptr != NULL) free (dbm->_dbm_memory.dptr); dbm->_dbm_memory = ret_val; - + __gdbm_error_to_ndbm (dbm); /* Return the new value. */ return ret_val; } diff --git a/compat/dbmstore.c b/compat/dbmstore.c index 1b6636a..76c6232 100644 --- a/compat/dbmstore.c +++ b/compat/dbmstore.c @@ -29,5 +29,7 @@ int dbm_store (DBM *dbm, datum key, datum content, int flags) { - return gdbm_store (dbm->file, key, content, flags); + int rc = gdbm_store (dbm->file, key, content, flags); + __gdbm_error_to_ndbm (dbm); + return rc; } diff --git a/compat/ndbm.h b/compat/ndbm.h index f6607bc..b19e61a 100644 --- a/compat/ndbm.h +++ b/compat/ndbm.h @@ -28,8 +28,8 @@ #include <gdbm.h> /* Parameters to dbm_store for simple insertion or replacement. */ -#define DBM_INSERT GDBM_INSERT -#define DBM_REPLACE GDBM_REPLACE +#define DBM_INSERT GDBM_INSERT +#define DBM_REPLACE GDBM_REPLACE /* The file information header. */ typedef struct @@ -38,9 +38,19 @@ typedef struct int dirfd; /* Descriptor of the .dir file */ datum _dbm_memory; /* Keeps the last returned key */ char *_dbm_fetch_val; /* Keeps the dptr of the last fetched datum */ + gdbm_error _dbm_errno; /* Error code from the last failed call */ } DBM; -/* These are the routines (with some macros defining them!) */ +/* Used internally by the library */ +#define __gdbm_error_to_ndbm(dbm) \ + do \ + { \ + if (gdbm_errno && gdbm_errno != GDBM_ITEM_NOT_FOUND) \ + (dbm)->_dbm_errno = gdbm_errno; \ + } \ + while (0) + +/* These are the routines */ extern DBM *dbm_open (char *file, int flags, int mode); extern void dbm_close (DBM *dbf); @@ -49,8 +59,8 @@ extern int dbm_store (DBM *dbf, datum key, datum content, int flags); extern int dbm_delete (DBM *dbf, datum key); extern datum dbm_firstkey (DBM *dbf); extern datum dbm_nextkey (DBM *dbf); -#define dbm_error(dbf) (0) -#define dbm_clearerr(dbf) +extern int dbm_error (DBM *dbf); +extern void dbm_clearerr (DBM *dbf); extern int dbm_dirfno (DBM *dbf); extern int dbm_pagfno (DBM *dbf); extern int dbm_rdonly (DBM *dbf); |