aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog16
-rw-r--r--compat/Makefile.am1
-rw-r--r--compat/dbmdelete.c5
-rw-r--r--compat/dbmerr.c32
-rw-r--r--compat/dbmfetch.c2
-rw-r--r--compat/dbmopen.c2
-rw-r--r--compat/dbmseq.c4
-rw-r--r--compat/dbmstore.c4
-rw-r--r--compat/ndbm.h20
9 files changed, 75 insertions, 11 deletions
diff --git a/ChangeLog b/ChangeLog
index 8a2df9d..433c558 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,19 @@
+2011-08-09 Sergey Poznyakoff <gray@gnu.org.ua>
+
+ 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.
+
2011-08-08 Sergey Poznyakoff <gray@gnu.org.ua>
Provide test group descriptors in the testsuite.
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);

Return to:

Send suggestions and report system problems to the System administrator.