summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org.ua>2016-07-09 05:40:04 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2016-07-09 05:47:16 (GMT)
commit479a469033903a76b9c073806037dd66176f3da0 (patch) (side-by-side diff)
tree2841b611288f9343868e6ded82909b096a62e121
parent2efd8358711ab3ea6c0ecaab75d195837b4b3e37 (diff)
downloadgdbm-479a469033903a76b9c073806037dd66176f3da0.tar.gz
gdbm-479a469033903a76b9c073806037dd66176f3da0.tar.bz2
Per-database error state.
Last error code is stored in the database file structure as well as in the global gdbm_errno. Special functions are provided for retrieving and clearing the last error state. * src/gdbmdefs.h (gdbm_file_info): New member: last_error * src/gdbm.h.in (gdbm_last_errno, gdbm_set_errno) (gdbm_clear_error): New protos. * src/gdbmerrno.c (gdbm_last_errno, gdbm_set_errno) (gdbm_clear_error): New functions * NEWS: Update. * compat/dbminit.c: Use gdbm_set_errno to set error state. * compat/dbmopen.c: Likewise. * src/bucket.c: Likewise. * src/findkey.c: Likewise. * src/gdbm_load.c: Likewise. * src/gdbmcount.c: Likewise. * src/gdbmdelete.c: Likewise. * src/gdbmdump.c: Likewise. * src/gdbmexists.c: Likewise. * src/gdbmexp.c: Likewise. * src/gdbmfetch.c: Likewise. * src/gdbmimp.c: Likewise. * src/gdbmload.c: Likewise. * src/gdbmopen.c: Likewise. * src/gdbmreorg.c: Likewise. * src/gdbmseq.c: Likewise. * src/gdbmsetopt.c: Likewise. * src/gdbmstore.c: Likewise. * src/gdbmsync.c: Likewise. * src/mmap.c: Likewise.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--NEWS10
-rw-r--r--compat/dbminit.c2
-rw-r--r--compat/dbmopen.c24
-rw-r--r--src/bucket.c8
-rw-r--r--src/findkey.c2
-rw-r--r--src/gdbm.h.in4
-rw-r--r--src/gdbm_load.c6
-rw-r--r--src/gdbmcount.c5
-rw-r--r--src/gdbmdefs.h6
-rw-r--r--src/gdbmdelete.c4
-rw-r--r--src/gdbmdump.c18
-rw-r--r--src/gdbmerrno.c36
-rw-r--r--src/gdbmexists.c4
-rw-r--r--src/gdbmexp.c12
-rw-r--r--src/gdbmfetch.c4
-rw-r--r--src/gdbmimp.c12
-rw-r--r--src/gdbmload.c14
-rw-r--r--src/gdbmopen.c65
-rw-r--r--src/gdbmreorg.c20
-rw-r--r--src/gdbmseq.c10
-rw-r--r--src/gdbmsetopt.c79
-rw-r--r--src/gdbmstore.c12
-rw-r--r--src/gdbmsync.c6
-rw-r--r--src/mmap.c8
24 files changed, 221 insertions, 150 deletions
diff --git a/NEWS b/NEWS
index a4f1129..4efabdb 100644
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,4 @@
-GNU dbm NEWS -- history of user-visible changes. 2016-07-08
+GNU dbm NEWS -- history of user-visible changes. 2016-07-09
Copyright (C) 1990-2016 Free Software Foundation, Inc.
See the end of file for copying conditions.
@@ -21,6 +21,14 @@ return.
The gdbm_fetch function no longer aborts on memory allocation errors.
Instead it sets gdbm_errno to GDBM_MALLOC_ERROR and returns NULL datum.
+* Per-database error codes
+
+* New functions
+
+** gdbm_last_errno
+
+** gdbm_clear_error
+
Version 1.12, 2016-05-16
diff --git a/compat/dbminit.c b/compat/dbminit.c
index 94ddc22..f5c5a65 100644
--- a/compat/dbminit.c
+++ b/compat/dbminit.c
@@ -48,7 +48,7 @@ dbminit (char *file)
/* Did we successfully open the file? */
if (_gdbm_file == NULL)
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1);
return -1;
}
}
diff --git a/compat/dbmopen.c b/compat/dbmopen.c
index 7a5127e..f8df3e3 100644
--- a/compat/dbmopen.c
+++ b/compat/dbmopen.c
@@ -71,7 +71,7 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
if (fstat (pagfd, &pagst))
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR; /* FIXME: special code? */
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1); /* FIXME: special code? */
return -1;
}
@@ -89,14 +89,14 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
return pagfd;
else
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1);
return -1;
}
}
}
else
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1);
return -1;
}
}
@@ -104,7 +104,7 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
/* ok */;
else if (st.st_size != DEF_DIR_SIZE)
{
- gdbm_errno = GDBM_BAD_MAGIC_NUMBER;
+ gdbm_set_errno (NULL, GDBM_BAD_MAGIC_NUMBER, 1);
return -1;
}
else
@@ -112,13 +112,13 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
fd = open (file_name, flags);
if (fd == -1)
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1);
return fd;
}
if (read (fd, dirbuf, sizeof (dirbuf)) != sizeof (dirbuf))
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 1);
close (fd);
return -1;
}
@@ -135,7 +135,7 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
return fd;
}
close (fd);
- gdbm_errno = GDBM_BAD_MAGIC_NUMBER;
+ gdbm_set_errno (NULL, GDBM_BAD_MAGIC_NUMBER, 1);
return -1;
}
}
@@ -151,7 +151,7 @@ ndbm_open_dir_file0 (const char *file_name, int pagfd, int mode)
if (write (fd, dirbuf, sizeof (dirbuf)) != sizeof (dirbuf))
{
- gdbm_errno = GDBM_FILE_WRITE_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_WRITE_ERROR, 1);
close (fd);
fd = -1;
}
@@ -168,7 +168,7 @@ ndbm_open_dir_file (const char *base, int pagfd, int mode)
if (!file_name)
{
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 1);
return -1;
}
fd = ndbm_open_dir_file0 (strcat (strcpy (file_name, base), DIRSUF),
@@ -212,7 +212,7 @@ dbm_open (char *file, int flags, int mode)
pag_file = (char *) malloc (strlen (file) + 5);
if (!pag_file)
{
- gdbm_errno = GDBM_MALLOC_ERROR; /* For the hell of it. */
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 1); /* For the hell of it. */
return NULL;
}
@@ -250,7 +250,7 @@ dbm_open (char *file, int flags, int mode)
if (!dbm)
{
free (pag_file);
- gdbm_errno = GDBM_MALLOC_ERROR; /* For the hell of it. */
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 1); /* For the hell of it. */
return NULL;
}
@@ -259,7 +259,7 @@ dbm_open (char *file, int flags, int mode)
/* Did we successfully open the file? */
if (dbm->file == NULL)
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (dbm, GDBM_FILE_OPEN_ERROR, 1);
free (dbm);
dbm = NULL;
}
diff --git a/src/bucket.c b/src/bucket.c
index c9a951c..ee0e157 100644
--- a/src/bucket.c
+++ b/src/bucket.c
@@ -1,8 +1,8 @@
/* bucket.c - The routines for playing with hash buckets. */
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013 Free Software Foundation,
- Inc.
+ Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013,
+ 2016 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
@@ -131,13 +131,13 @@ _gdbm_read_bucket_at (GDBM_FILE dbf, off_t off, hash_bucket *bucket,
file_pos = __lseek (dbf, off, SEEK_SET);
if (file_pos != off)
{
- gdbm_errno = GDBM_FILE_SEEK_ERROR;
+ gdbm_set_errno (dbf, GDBM_FILE_SEEK_ERROR, 1);
return -1;
}
rc = _gdbm_full_read (dbf, bucket, size);
if (rc)
{
- gdbm_errno = rc;
+ gdbm_set_errno (dbf, rc, 1);
return -1;
}
return 0;
diff --git a/src/findkey.c b/src/findkey.c
index b4b3bd2..6b13fbf 100644
--- a/src/findkey.c
+++ b/src/findkey.c
@@ -149,7 +149,7 @@ _gdbm_findkey (GDBM_FILE dbf, datum key, char **ret_dptr, int *ret_hash_val)
}
/* If we get here, we never found the key. */
- gdbm_errno = GDBM_ITEM_NOT_FOUND;
+ gdbm_set_errno (dbf, GDBM_ITEM_NOT_FOUND, 0);
return -1;
}
diff --git a/src/gdbm.h.in b/src/gdbm.h.in
index f8238b9..07ac4dc 100644
--- a/src/gdbm.h.in
+++ b/src/gdbm.h.in
@@ -177,6 +177,10 @@ typedef int gdbm_error; /* For compatibilities sake. */
extern gdbm_error gdbm_errno;
extern const char * const gdbm_errlist[];
+extern int gdbm_last_errno (GDBM_FILE dbf);
+extern void gdbm_set_errno (GDBM_FILE dbf, gdbm_error ec, int fatal);
+extern void gdbm_clear_error (GDBM_FILE dbf);
+
/* extra prototypes */
extern const char *gdbm_strerror (gdbm_error);
diff --git a/src/gdbm_load.c b/src/gdbm_load.c
index 260a601..fd404b9 100644
--- a/src/gdbm_load.c
+++ b/src/gdbm_load.c
@@ -1,5 +1,5 @@
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 2011, 2013 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2013, 2016 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
@@ -53,13 +53,13 @@ set_meta_info (GDBM_FILE dbf)
{
if (fchown (fd, owner_uid, owner_gid))
{
- gdbm_errno = GDBM_ERR_FILE_OWNER;
+ gdbm_set_errno (dbf, GDBM_ERR_FILE_OWNER, 0);
return 1;
}
}
if ((meta_mask & GDBM_META_MASK_MODE) && fchmod (fd, mode))
{
- gdbm_errno = GDBM_ERR_FILE_OWNER;
+ gdbm_set_errno (dbf, GDBM_ERR_FILE_OWNER, 0);
return 1;
}
}
diff --git a/src/gdbmcount.c b/src/gdbmcount.c
index 8e22213..17016b2 100644
--- a/src/gdbmcount.c
+++ b/src/gdbmcount.c
@@ -1,7 +1,8 @@
/* gdbmcount.c - get number of items in a gdbm file. */
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 1993, 1994, 2007, 2011, 2013 Free Software Foundation, Inc.
+ Copyright (C) 1993, 1994, 2007, 2011, 2013,
+ 2016 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
@@ -42,7 +43,7 @@ gdbm_count (GDBM_FILE dbf, gdbm_count_t *pcount)
sdir = malloc (dbf->header->dir_size);
if (!sdir)
{
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (dbf, GDBM_MALLOC_ERROR, 0);
return -1;
}
diff --git a/src/gdbmdefs.h b/src/gdbmdefs.h
index c62413b..e873117 100644
--- a/src/gdbmdefs.h
+++ b/src/gdbmdefs.h
@@ -159,6 +159,12 @@ struct gdbm_file_info {
/* Whether the database was open with GDBM_CLOEXEC flag */
unsigned cloexec :1;
+
+ /* Last error was fatal */
+ unsigned fatal :1;
+
+ /* Last error number */
+ int last_error;
/* Type of file locking in use. */
enum { LOCKING_NONE = 0, LOCKING_FLOCK, LOCKING_LOCKF,
diff --git a/src/gdbmdelete.c b/src/gdbmdelete.c
index 4396b14..7e2867d 100644
--- a/src/gdbmdelete.c
+++ b/src/gdbmdelete.c
@@ -39,12 +39,12 @@ gdbm_delete (GDBM_FILE dbf, datum key)
/* First check to make sure this guy is a writer. */
if (dbf->read_write == GDBM_READER)
{
- gdbm_errno = GDBM_READER_CANT_DELETE;
+ gdbm_set_errno (dbf, GDBM_READER_CANT_DELETE, 0);
return -1;
}
/* Initialize the gdbm_errno variable. */
- gdbm_errno = GDBM_NO_ERROR;
+ gdbm_set_errno (dbf, GDBM_NO_ERROR, 0);
/* Find the item. */
elem_loc = _gdbm_findkey (dbf, key, NULL, NULL);
diff --git a/src/gdbmdump.c b/src/gdbmdump.c
index 1b374f3..cf1e2fc 100644
--- a/src/gdbmdump.c
+++ b/src/gdbmdump.c
@@ -1,5 +1,5 @@
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 2011, 2013 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2013, 2016 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
@@ -99,7 +99,7 @@ _gdbm_dump_ascii (GDBM_FILE dbf, FILE *fp)
{
free (key.dptr);
free (data.dptr);
- gdbm_errno = rc;
+ gdbm_set_errno (dbf, rc, 0);
break;
}
}
@@ -139,11 +139,15 @@ gdbm_dump_to_file (GDBM_FILE dbf, FILE *fp, int format)
break;
default:
+ gdbm_set_errno (NULL, GDBM_BAD_OPEN_FLAGS, 0);
return EINVAL;
}
if (rc == 0 && ferror (fp))
- rc = gdbm_errno = GDBM_FILE_WRITE_ERROR;
+ {
+ gdbm_set_errno (NULL, GDBM_FILE_WRITE_ERROR, 0);
+ rc = -1;
+ }
return rc;
}
@@ -162,7 +166,7 @@ gdbm_dump (GDBM_FILE dbf, const char *filename, int fmt, int open_flags,
nfd = open (filename, O_WRONLY | O_CREAT | O_EXCL, mode);
if (nfd == -1)
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 0);
return -1;
}
break;
@@ -170,12 +174,12 @@ gdbm_dump (GDBM_FILE dbf, const char *filename, int fmt, int open_flags,
nfd = open (filename, O_WRONLY | O_CREAT | O_TRUNC, mode);
if (nfd == -1)
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 0);
return -1;
}
break;
default:
- gdbm_errno = GDBM_BAD_OPEN_FLAGS;
+ gdbm_set_errno (NULL, GDBM_BAD_OPEN_FLAGS, 0);
return -1;
}
@@ -183,7 +187,7 @@ gdbm_dump (GDBM_FILE dbf, const char *filename, int fmt, int open_flags,
if (!fp)
{
close (nfd);
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 0);
return -1;
}
rc = gdbm_dump_to_file (dbf, fp, fmt);
diff --git a/src/gdbmerrno.c b/src/gdbmerrno.c
index 3b5cf4c..2ff647f 100644
--- a/src/gdbmerrno.c
+++ b/src/gdbmerrno.c
@@ -1,7 +1,7 @@
/* gdbmerrno.c - convert gdbm errors into english. */
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 1993, 2007, 2011, 2013 Free Software Foundation, Inc.
+ Copyright (C) 1993, 2007, 2011, 2013, 2016 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
@@ -24,6 +24,40 @@
/* The dbm error number is placed in the variable GDBM_ERRNO. */
gdbm_error gdbm_errno = GDBM_NO_ERROR;
+/* Store error code EC in the database structure DBF and in the
+ global variable gdbm_error.
+*/
+void
+gdbm_set_errno (GDBM_FILE dbf, gdbm_error ec, int fatal)
+{
+ if (dbf)
+ {
+ dbf->last_error = ec;
+ dbf->fatal = fatal;
+ }
+ gdbm_errno = ec;
+}
+
+/* Retrieve last error code for the database DBF. */
+int
+gdbm_last_errno (GDBM_FILE dbf)
+{
+ if (!dbf)
+ {
+ errno = EINVAL;
+ return -1;
+ }
+ return dbf->last_error;
+}
+
+/* Clear error state for the database DBF. */
+void
+gdbm_clear_error (GDBM_FILE dbf)
+{
+ if (dbf)
+ dbf->last_error = GDBM_NO_ERROR;
+}
+
/* this is not static so that applications may access the array if they
like. */
diff --git a/src/gdbmexists.c b/src/gdbmexists.c
index 9bbd308..0d551c0 100644
--- a/src/gdbmexists.c
+++ b/src/gdbmexists.c
@@ -1,7 +1,7 @@
/* gdbmexists.c - Check to see if a key exists */
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 1993, 2007, 2011, 2013 Free Software Foundation, Inc.
+ Copyright (C) 1993, 2007, 2011, 2013, 2016 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
@@ -30,7 +30,7 @@ gdbm_exists (GDBM_FILE dbf, datum key)
if (_gdbm_findkey (dbf, key, NULL, NULL) < 0)
{
if (gdbm_errno == GDBM_ITEM_NOT_FOUND)
- gdbm_errno = GDBM_NO_ERROR;
+ gdbm_set_errno (dbf, GDBM_NO_ERROR, 0);
return 0;
}
return 1;
diff --git a/src/gdbmexp.c b/src/gdbmexp.c
index e68457f..613166e 100644
--- a/src/gdbmexp.c
+++ b/src/gdbmexp.c
@@ -81,7 +81,7 @@ gdbm_export_to_file (GDBM_FILE dbf, FILE *fp)
write_fail:
- gdbm_errno = GDBM_FILE_WRITE_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_WRITE_ERROR, 0);
return -1;
}
@@ -98,7 +98,7 @@ gdbm_export (GDBM_FILE dbf, const char *exportfile, int flags, int mode)
nfd = open (exportfile, O_WRONLY | O_CREAT | O_EXCL, mode);
if (nfd == -1)
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 0);
return -1;
}
break;
@@ -106,15 +106,15 @@ gdbm_export (GDBM_FILE dbf, const char *exportfile, int flags, int mode)
nfd = open (exportfile, O_WRONLY | O_CREAT | O_TRUNC, mode);
if (nfd == -1)
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 0);
return -1;
}
break;
default:
#ifdef GDBM_BAD_OPEN_FLAGS
- gdbm_errno = GDBM_BAD_OPEN_FLAGS;
+ gdbm_set_errno (NULL, GDBM_BAD_OPEN_FLAGS, 0);
#else
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 0);
#endif
return -1;
}
@@ -123,7 +123,7 @@ gdbm_export (GDBM_FILE dbf, const char *exportfile, int flags, int mode)
if (!fp)
{
close (nfd);
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 0);
return -1;
}
diff --git a/src/gdbmfetch.c b/src/gdbmfetch.c
index a765c52..ca82550 100644
--- a/src/gdbmfetch.c
+++ b/src/gdbmfetch.c
@@ -38,7 +38,7 @@ gdbm_fetch (GDBM_FILE dbf, datum key)
return_val.dsize = 0;
/* Initialize the gdbm_errno variable. */
- gdbm_errno = GDBM_NO_ERROR;
+ gdbm_set_errno (dbf, GDBM_NO_ERROR, 0);
/* Find the key and return a pointer to the data. */
elem_loc = _gdbm_findkey (dbf, key, &find_data, NULL);
@@ -54,7 +54,7 @@ gdbm_fetch (GDBM_FILE dbf, datum key)
return_val.dptr = (char *) malloc (return_val.dsize);
if (return_val.dptr == NULL)
{
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (dbf, GDBM_MALLOC_ERROR, 0);
return return_val;
}
memcpy (return_val.dptr, find_data, return_val.dsize);
diff --git a/src/gdbmimp.c b/src/gdbmimp.c
index 31092aa..96c774f 100644
--- a/src/gdbmimp.c
+++ b/src/gdbmimp.c
@@ -1,7 +1,7 @@
/* gdbmimp.c - Import a GDBM database. */
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 2007, 2011, 2013 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2011, 2013, 2016 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
@@ -44,7 +44,7 @@ gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag)
{
if ((rret = fgetc (fp)) == -1)
{
- gdbm_errno = GDBM_FILE_READ_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_READ_ERROR, 0);
return -1;
}
@@ -66,7 +66,7 @@ gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag)
kbuffer = malloc (kbufsize);
if (kbuffer == NULL)
{
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 0);
return -1;
}
dbufsize = 512;
@@ -74,7 +74,7 @@ gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag)
if (dbuffer == NULL)
{
free (kbuffer);
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 0);
return -1;
}
@@ -160,7 +160,7 @@ gdbm_import_from_file (GDBM_FILE dbf, FILE *fp, int flag)
if (ec == GDBM_NO_ERROR)
return count;
- gdbm_errno = ec;
+ gdbm_set_errno (NULL, ec, 0);
return -1;
}
@@ -173,7 +173,7 @@ gdbm_import (GDBM_FILE dbf, const char *importfile, int flag)
fp = fopen (importfile, "r");
if (!fp)
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 0);
return -1;
}
rc = gdbm_import_from_file (dbf, fp, flag);
diff --git a/src/gdbmload.c b/src/gdbmload.c
index 19ee0fb..5723b95 100644
--- a/src/gdbmload.c
+++ b/src/gdbmload.c
@@ -1,5 +1,5 @@
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 2011, 2013 Free Software Foundation, Inc.
+ Copyright (C) 2011, 2013, 2016 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
@@ -373,13 +373,13 @@ _set_gdbm_meta_info (GDBM_FILE dbf, char *param, int meta_mask)
}
if (fchown (fd, owner_uid, owner_gid))
{
- gdbm_errno = GDBM_ERR_FILE_OWNER;
+ gdbm_set_errno (dbf, GDBM_ERR_FILE_OWNER, 0);
rc = 1;
}
}
if ((meta_flags & META_MODE) && fchmod (fd, mode))
{
- gdbm_errno = GDBM_ERR_FILE_OWNER;
+ gdbm_set_errno (dbf, GDBM_ERR_FILE_OWNER, 0);
rc = 1;
}
}
@@ -581,7 +581,7 @@ gdbm_load_from_file (GDBM_FILE *pdbf, FILE *fp, int replace,
*line = 0;
if (!*pdbf)
{
- gdbm_errno = GDBM_NO_DBNAME;
+ gdbm_set_errno (NULL, GDBM_NO_DBNAME, 0);
return -1;
}
if (gdbm_import_from_file (*pdbf, fp, replace) == -1)
@@ -596,7 +596,7 @@ gdbm_load_from_file (GDBM_FILE *pdbf, FILE *fp, int replace,
{
if (!*pdbf)
{
- gdbm_errno = GDBM_NO_DBNAME;
+ gdbm_set_errno (NULL, GDBM_NO_DBNAME, 0);
return -1;
}
rc = gdbm_load_bdb_dump (&df, *pdbf, replace);
@@ -608,7 +608,7 @@ gdbm_load_from_file (GDBM_FILE *pdbf, FILE *fp, int replace,
{
if (line)
*line = df.line;
- gdbm_errno = rc;
+ gdbm_set_errno (NULL, rc, 0);
return -1;
}
return 0;
@@ -625,7 +625,7 @@ gdbm_load (GDBM_FILE *pdbf, const char *filename, int replace,
fp = fopen (filename, "r");
if (!fp)
{
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 0);
return -1;
}
rc = gdbm_load_from_file (pdbf, fp, replace, meta_mask, line);
diff --git a/src/gdbmopen.c b/src/gdbmopen.c
index 14c687d..b8b14e3 100644
--- a/src/gdbmopen.c
+++ b/src/gdbmopen.c
@@ -1,8 +1,8 @@
/* gdbmopen.c - Open the dbm file and initialize data structures for use. */
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013 Free Software Foundation,
- Inc.
+ Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013,
+ 2016 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
@@ -67,13 +67,13 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
int fbits = 0; /* additional bits for open(2) flags */
/* Initialize the gdbm_errno variable. */
- gdbm_errno = GDBM_NO_ERROR;
+ gdbm_set_errno (NULL, GDBM_NO_ERROR, 0);
/* Allocate new info structure. */
dbf = (GDBM_FILE) malloc (sizeof (*dbf));
if (dbf == NULL)
{
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 0);
return NULL;
}
@@ -98,7 +98,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (dbf->name == NULL)
{
free (dbf);
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 0);
return NULL;
}
strcpy (dbf->name, file);
@@ -155,7 +155,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
{
SAVE_ERRNO (free (dbf->name);
free (dbf));
- gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_OPEN_ERROR, 0);
return NULL;
}
@@ -165,7 +165,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
SAVE_ERRNO (close (dbf->desc);
free (dbf->name);
free (dbf));
- gdbm_errno = GDBM_FILE_STAT_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_STAT_ERROR, 0);
return NULL;
}
@@ -175,7 +175,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
close (dbf->desc);
free (dbf->name);
free (dbf);
- gdbm_errno = GDBM_EMPTY_DATABASE;
+ gdbm_set_errno (NULL, GDBM_EMPTY_DATABASE, 0);
return NULL;
}
@@ -190,10 +190,9 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
close (dbf->desc);
free (dbf->name);
free (dbf);
- if ((flags & GDBM_OPENMASK) == GDBM_READER)
- gdbm_errno = GDBM_CANT_BE_READER;
- else
- gdbm_errno = GDBM_CANT_BE_WRITER;
+ gdbm_set_errno (NULL,
+ (flags & GDBM_OPENMASK) == GDBM_READER
+ ? GDBM_CANT_BE_READER : GDBM_CANT_BE_WRITER, 0);
return NULL;
}
}
@@ -224,7 +223,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (dbf->header == NULL)
{
gdbm_close (dbf);
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 0);
return NULL;
}
@@ -245,7 +244,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (dbf->header->dir_size != dbf->header->block_size)
{
gdbm_close (dbf);
- gdbm_errno = GDBM_BLOCK_SIZE_ERROR;
+ gdbm_set_errno (NULL, GDBM_BLOCK_SIZE_ERROR, 0);
return NULL;
}
@@ -254,7 +253,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (dbf->dir == NULL)
{
gdbm_close (dbf);
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 0);
return NULL;
}
dbf->header->dir = dbf->header->block_size;
@@ -268,7 +267,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (dbf->bucket == NULL)
{
gdbm_close (dbf);
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 0);
return NULL;
}
_gdbm_new_bucket (dbf, dbf->bucket, 0);
@@ -294,7 +293,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (rc)
{
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_errno = rc;
+ gdbm_set_errno (NULL, rc, 0);
return NULL;
}
@@ -303,7 +302,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (rc)
{
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_errno = rc;
+ gdbm_set_errno (NULL, rc, 0);
return NULL;
}
@@ -312,7 +311,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (rc)
{
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_errno = rc;
+ gdbm_set_errno (NULL, rc, 0);
return NULL;
}
@@ -333,7 +332,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (rc)
{
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_errno = rc;
+ gdbm_set_errno (NULL, rc, 0);
return NULL;
}
@@ -347,14 +346,14 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
case GDBM_OMAGIC_SWAP:
case GDBM_MAGIC32_SWAP:
case GDBM_MAGIC64_SWAP:
- gdbm_errno = GDBM_BYTE_SWAPPED;
+ gdbm_set_errno (NULL, GDBM_BYTE_SWAPPED, 0);
break;
case GDBM_MAGIC32:
case GDBM_MAGIC64:
- gdbm_errno = GDBM_BAD_FILE_OFFSET;
+ gdbm_set_errno (NULL, GDBM_BAD_FILE_OFFSET, 0);
break;
default:
- gdbm_errno = GDBM_BAD_MAGIC_NUMBER;
+ gdbm_set_errno (NULL, GDBM_BAD_MAGIC_NUMBER, 0);
}
return NULL;
}
@@ -364,7 +363,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (dbf->header == NULL)
{
gdbm_close (dbf);
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 0);
return NULL;
}
memcpy (dbf->header, &partial_header, sizeof (gdbm_file_header));
@@ -373,7 +372,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (rc)
{
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_errno = rc;
+ gdbm_set_errno (NULL, rc, 0);
return NULL;
}
@@ -382,7 +381,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (dbf->dir == NULL)
{
gdbm_close (dbf);
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (NULL, GDBM_MALLOC_ERROR, 0);
return NULL;
}
@@ -391,7 +390,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (file_pos != dbf->header->dir)
{
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_errno = GDBM_FILE_SEEK_ERROR;
+ gdbm_set_errno (NULL, GDBM_FILE_SEEK_ERROR, 0);
return NULL;
}
@@ -399,7 +398,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
if (rc)
{
SAVE_ERRNO (gdbm_close (dbf));
- gdbm_errno = rc;
+ gdbm_set_errno (NULL, rc, 0);
return NULL;
}
@@ -413,9 +412,9 @@ gdbm_open (const char *file, int block_size, int flags, int mode,
else
{
/* gdbm_errno should already be set. */
- close (dbf->desc);
- free (dbf->name);
- free (dbf);
+ SAVE_ERRNO (close (dbf->desc);
+ free (dbf->name);
+ free (dbf));
return NULL;
}
}
@@ -448,7 +447,7 @@ _gdbm_init_cache(GDBM_FILE dbf, size_t size)
dbf->bucket_cache = (cache_elem *) malloc(sizeof(cache_elem) * size);
if(dbf->bucket_cache == NULL)
{
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (dbf, GDBM_MALLOC_ERROR, 1);
return -1;
}
dbf->cache_size = size;
@@ -459,7 +458,7 @@ _gdbm_init_cache(GDBM_FILE dbf, size_t size)
= (hash_bucket *) malloc (dbf->header->bucket_size);
if ((dbf->bucket_cache[index]).ca_bucket == NULL)
{
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (dbf, GDBM_MALLOC_ERROR, 1);
return -1;
}
(dbf->bucket_cache[index]).ca_adr = 0;
diff --git a/src/gdbmreorg.c b/src/gdbmreorg.c
index 7e554cb..360f5c8 100644
--- a/src/gdbmreorg.c
+++ b/src/gdbmreorg.c
@@ -1,8 +1,8 @@
/* gdbmreorg.c - Reorganize the database file. */
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013 Free Software Foundation,
- Inc.
+ Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013,
+ 2016 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
@@ -69,26 +69,26 @@ gdbm_reorganize (GDBM_FILE dbf)
/* Readers can not reorganize! */
if (dbf->read_write == GDBM_READER)
{
- gdbm_errno = GDBM_READER_CANT_REORGANIZE;
+ gdbm_set_errno (dbf, GDBM_READER_CANT_REORGANIZE, 0);
return -1;
}
/* Get the mode for the old file */
if (fstat (dbf->desc, &fileinfo))
{
- gdbm_errno = GDBM_FILE_STAT_ERROR;
+ gdbm_set_errno (dbf, GDBM_FILE_STAT_ERROR, 0);
return -1;
}
/* Initialize the gdbm_errno variable. */
- gdbm_errno = GDBM_NO_ERROR;
+ gdbm_set_errno (dbf, GDBM_NO_ERROR, 0);
/* Construct new name for temporary file. */
len = strlen (dbf->name);
new_name = (char *) malloc (len + 3);
if (new_name == NULL)
{
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (dbf, GDBM_MALLOC_ERROR, 0);
return -1;
}
strcpy (&new_name[0], dbf->name);
@@ -109,7 +109,7 @@ gdbm_reorganize (GDBM_FILE dbf)
if (new_dbf == NULL)
{
free (new_name);
- gdbm_errno = GDBM_REORGANIZE_FAILED;
+ gdbm_set_errno (NULL, GDBM_REORGANIZE_FAILED, 0);
return -1;
}
@@ -126,7 +126,7 @@ gdbm_reorganize (GDBM_FILE dbf)
if (gdbm_store (new_dbf, key, data, GDBM_INSERT) != 0)
{
gdbm_close (new_dbf);
- gdbm_errno = GDBM_REORGANIZE_FAILED;
+ gdbm_set_errno (NULL, GDBM_REORGANIZE_FAILED, 0);
unlink (new_name);
free (new_name);
return -1;
@@ -136,7 +136,7 @@ gdbm_reorganize (GDBM_FILE dbf)
{
/* ERROR! Abort and don't finish reorganize. */
gdbm_close (new_dbf);
- gdbm_errno = GDBM_REORGANIZE_FAILED;
+ gdbm_set_errno (NULL, GDBM_REORGANIZE_FAILED, 0);
unlink (new_name);
free (new_name);
return -1;
@@ -159,7 +159,7 @@ gdbm_reorganize (GDBM_FILE dbf)
if (rename (new_name, dbf->name) != 0)
{
- gdbm_errno = GDBM_REORGANIZE_FAILED;
+ gdbm_set_errno (NULL, GDBM_REORGANIZE_FAILED, 0);
gdbm_close (new_dbf);
free (new_name);
return -1;
diff --git a/src/gdbmseq.c b/src/gdbmseq.c
index 0742383..c62a13b 100644
--- a/src/gdbmseq.c
+++ b/src/gdbmseq.c
@@ -65,7 +65,7 @@ get_next_key (GDBM_FILE dbf, int elem_loc, datum *return_val)
else
{
/* No next key, just return. */
- gdbm_errno = GDBM_ITEM_NOT_FOUND;
+ gdbm_set_errno (dbf, GDBM_ITEM_NOT_FOUND, 0);
return;
}
}
@@ -82,7 +82,7 @@ get_next_key (GDBM_FILE dbf, int elem_loc, datum *return_val)
if (return_val->dptr == NULL)
{
return_val->dsize = 0;
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (dbf, GDBM_MALLOC_ERROR, 0);
}
else
memcpy (return_val->dptr, find_data, return_val->dsize);
@@ -101,7 +101,7 @@ gdbm_firstkey (GDBM_FILE dbf)
return_val.dptr = NULL;
/* Initialize the gdbm_errno variable. */
- gdbm_errno = GDBM_NO_ERROR;
+ gdbm_set_errno (dbf, GDBM_NO_ERROR, 0);
/* Get the first bucket. */
_gdbm_get_bucket (dbf, 0);
@@ -122,7 +122,7 @@ gdbm_nextkey (GDBM_FILE dbf, datum key)
int elem_loc; /* The location in the bucket. */
/* Initialize the gdbm_errno variable. */
- gdbm_errno = GDBM_NO_ERROR;
+ gdbm_set_errno (dbf, GDBM_NO_ERROR, 0);
/* Set the default return value for no next entry. */
return_val.dptr = NULL;
@@ -130,7 +130,7 @@ gdbm_nextkey (GDBM_FILE dbf, datum key)
/* Do we have a valid key? */
if (key.dptr == NULL)
{
- gdbm_errno = GDBM_ITEM_NOT_FOUND; /* FIXME: special error code perhaps */
+ gdbm_set_errno (dbf, GDBM_ITEM_NOT_FOUND, 0); /* FIXME: special error code perhaps */
return return_val;
}
diff --git a/src/gdbmsetopt.c b/src/gdbmsetopt.c
index 23cdd9a..e372a92 100644
--- a/src/gdbmsetopt.c
+++ b/src/gdbmsetopt.c
@@ -1,7 +1,8 @@
/* gdbmsetopt.c - set options pertaining to a GDBM descriptor. */
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 1993, 1994, 2007, 2011, 2013 Free Software Foundation, Inc.
+ Copyright (C) 1993, 1994, 2007, 2011, 2013,
+ 2016 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
@@ -30,10 +31,7 @@ getbool (void *optval, int optlen)
if (!optval || optlen != sizeof (int) ||
(((n = *(int*)optval) != TRUE) && n != FALSE))
- {
- gdbm_errno = GDBM_OPT_ILLEGAL;
- return -1;
- }
+ return -1;
return n;
}
@@ -41,10 +39,7 @@ static int
get_size (void *optval, int optlen, size_t *ret)
{
if (!optval)
- {
- gdbm_errno = GDBM_OPT_ILLEGAL;
- return -1;
- }
+ return -1;
if (optlen == sizeof (unsigned))
*ret = *(unsigned*) optval;
else if (optlen == sizeof (unsigned long))
@@ -52,10 +47,7 @@ get_size (void *optval, int optlen, size_t *ret)
else if (optlen == sizeof (size_t))
*ret = *(size_t*) optval;
else
- {
- gdbm_errno = GDBM_OPT_ILLEGAL;
- return -1;
- }
+ return -1;
return 0;
}
@@ -73,18 +65,21 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
/* Optval will point to the new size of the cache. */
if (dbf->bucket_cache != NULL)
{
- gdbm_errno = GDBM_OPT_ALREADY_SET;
+ gdbm_set_errno (dbf, GDBM_OPT_ALREADY_SET, 0);
return -1;
}
if (get_size (optval, optlen, &sz))
- return -1;
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
+ return -1;
+ }
return _gdbm_init_cache (dbf, (sz > 9) ? sz : 10);
case GDBM_GETCACHESIZE:
if (!optval || optlen != sizeof (size_t))
{
- gdbm_errno = GDBM_OPT_ILLEGAL;
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
return -1;
}
*(size_t*) optval = dbf->cache_size;
@@ -93,7 +88,10 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
/* Obsolete form of GDBM_SETSYNCMODE. */
case GDBM_FASTMODE:
if ((n = getbool (optval, optlen)) == -1)
- return -1;
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
+ return -1;
+ }
dbf->fast_write = n;
break;
@@ -102,14 +100,17 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
case GDBM_SETSYNCMODE:
/* Optval will point to either true or false. */
if ((n = getbool (optval, optlen)) == -1)
- return -1;
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
+ return -1;
+ }
dbf->fast_write = !n;
break;
case GDBM_GETSYNCMODE:
if (!optval || optlen != sizeof (int))
{
- gdbm_errno = GDBM_OPT_ILLEGAL;
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
return -1;
}
*(int*) optval = !dbf->fast_write;
@@ -119,14 +120,17 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
case GDBM_SETCENTFREE:
/* Optval will point to either true or false. */
if ((n = getbool (optval, optlen)) == -1)
- return -1;
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
+ return -1;
+ }
dbf->central_free = n;
break;
case GDBM_GETCENTFREE:
if (!optval || optlen != sizeof (int))
{
- gdbm_errno = GDBM_OPT_ILLEGAL;
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
return -1;
}
*(int*) optval = !dbf->central_free;
@@ -136,14 +140,17 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
case GDBM_SETCOALESCEBLKS:
/* Optval will point to either true or false. */
if ((n = getbool (optval, optlen)) == -1)
- return -1;
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
+ return -1;
+ }
dbf->coalesce_blocks = n;
break;
case GDBM_GETCOALESCEBLKS:
if (!optval || optlen != sizeof (int))
{
- gdbm_errno = GDBM_OPT_ILLEGAL;
+ gdbm_set_errno (NULL, GDBM_OPT_ILLEGAL, 0);
return -1;
}
*(int*) optval = dbf->coalesce_blocks;
@@ -153,7 +160,10 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
case GDBM_SETMMAP:
#if HAVE_MMAP
if ((n = getbool (optval, optlen)) == -1)
- return -1;
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
+ return -1;
+ }
__fsync (dbf);
if (n == dbf->memory_mapping)
return 0;
@@ -170,7 +180,7 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
dbf->memory_mapping = FALSE;
}
#else
- gdbm_errno = GDBM_OPT_ILLEGAL;
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
return -1;
#endif
break;
@@ -178,7 +188,7 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
case GDBM_GETMMAP:
if (!optval || optlen != sizeof (int))
{
- gdbm_errno = GDBM_OPT_ILLEGAL;
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
return -1;
}
*(int*) optval = dbf->memory_mapping;
@@ -191,21 +201,24 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
size_t page_size = sysconf (_SC_PAGESIZE);
if (get_size (optval, optlen, &sz))
- return -1;
+ {
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
+ return -1;
+ }
dbf->mapped_size_max = ((sz + page_size - 1) / page_size) *
page_size;
_gdbm_mapped_init (dbf);
break;
}
#else
- gdbm_errno = GDBM_OPT_ILLEGAL;
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
return -1;
#endif
case GDBM_GETMAXMAPSIZE:
if (!optval || optlen != sizeof (size_t))
{
- gdbm_errno = GDBM_OPT_ILLEGAL;
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
return -1;
}
*(size_t*) optval = dbf->mapped_size_max;
@@ -215,7 +228,7 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
case GDBM_GETFLAGS:
if (!optval || optlen != sizeof (int))
{
- gdbm_errno = GDBM_OPT_ILLEGAL;
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
return -1;
}
else
@@ -234,7 +247,7 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
case GDBM_GETDBNAME:
if (!optval || optlen != sizeof (char*))
{
- gdbm_errno = GDBM_OPT_ILLEGAL;
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
return -1;
}
else
@@ -242,7 +255,7 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
char *p = strdup (dbf->name);
if (!p)
{
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (dbf, GDBM_MALLOC_ERROR, 0);
return -1;
}
*(char**) optval = p;
@@ -250,7 +263,7 @@ gdbm_setopt (GDBM_FILE dbf, int optflag, void *optval, int optlen)
break;
default:
- gdbm_errno = GDBM_OPT_ILLEGAL;
+ gdbm_set_errno (dbf, GDBM_OPT_ILLEGAL, 0);
return -1;
}
diff --git a/src/gdbmstore.c b/src/gdbmstore.c
index 3ba882e..f166ba9 100644
--- a/src/gdbmstore.c
+++ b/src/gdbmstore.c
@@ -50,7 +50,7 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
/* First check to make sure this guy is a writer. */
if (dbf->read_write == GDBM_READER)
{
- gdbm_errno = GDBM_READER_CANT_STORE;
+ gdbm_set_errno (dbf, GDBM_READER_CANT_STORE, 0);
return -1;
}
@@ -58,12 +58,12 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
NULL dptr returned by a lookup procedure indicates an error. */
if ((key.dptr == NULL) || (content.dptr == NULL))
{
- gdbm_errno = GDBM_ILLEGAL_DATA;
+ gdbm_set_errno (dbf, GDBM_ILLEGAL_DATA, 0);
return -1;
}
/* Initialize the gdbm_errno variable. */
- gdbm_errno = GDBM_NO_ERROR;
+ gdbm_set_errno (dbf, GDBM_NO_ERROR, 0);
/* Look for the key in the file.
A side effect loads the correct bucket and calculates the hash value. */
@@ -94,11 +94,13 @@ gdbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
}
else
{
- gdbm_errno = GDBM_CANNOT_REPLACE;
+ gdbm_set_errno (dbf, GDBM_CANNOT_REPLACE, 0);
return 1;
}
}
- else if (gdbm_errno != GDBM_ITEM_NOT_FOUND)
+ else if (gdbm_errno == GDBM_ITEM_NOT_FOUND)
+ gdbm_set_errno (dbf, GDBM_NO_ERROR, 0); //clear error state
+ else
return -1;
/* Get the file address for the new space.
diff --git a/src/gdbmsync.c b/src/gdbmsync.c
index 7635a75..c9b146c 100644
--- a/src/gdbmsync.c
+++ b/src/gdbmsync.c
@@ -1,8 +1,8 @@
/* gdbmsync.c - Sync the disk with the in memory state. */
/* This file is part of GDBM, the GNU data base manager.
- Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013 Free Software Foundation,
- Inc.
+ Copyright (C) 1990, 1991, 1993, 2007, 2011, 2013,
+ 2016 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
@@ -29,7 +29,7 @@ gdbm_sync (GDBM_FILE dbf)
{
/* Initialize the gdbm_errno variable. */
- gdbm_errno = GDBM_NO_ERROR;
+ gdbm_set_errno (dbf, GDBM_NO_ERROR, 0);
/* Do the sync on the file. */
__fsync (dbf);
diff --git a/src/mmap.c b/src/mmap.c
index b2f3a85..5e89b28 100644
--- a/src/mmap.c
+++ b/src/mmap.c
@@ -1,5 +1,5 @@
/* This file is part of GDBM.
- Copyright (C) 2007, 2011, 2013 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2011, 2013, 2016 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
@@ -99,7 +99,7 @@ _gdbm_internal_remap (GDBM_FILE dbf, size_t size)
if (p == MAP_FAILED)
{
dbf->mapped_region = NULL;
- gdbm_errno = GDBM_MALLOC_ERROR;
+ gdbm_set_errno (dbf, GDBM_MALLOC_ERROR, 0);
return -1;
}
@@ -135,7 +135,7 @@ _gdbm_mapped_remap (GDBM_FILE dbf, off_t size, int flag)
if (_gdbm_file_size (dbf, &file_size))
{
SAVE_ERRNO (_gdbm_mapped_unmap (dbf));
- gdbm_errno = GDBM_FILE_STAT_ERROR;
+ gdbm_set_errno (dbf, GDBM_FILE_STAT_ERROR, 0);
return -1;
}
@@ -330,7 +330,7 @@ _gdbm_mapped_lseek (GDBM_FILE dbf, off_t offset, int whence)
off_t file_size;
if (_gdbm_file_size (dbf, &file_size))
{
- gdbm_errno = GDBM_FILE_STAT_ERROR;
+ gdbm_set_errno (dbf, GDBM_FILE_STAT_ERROR, 0);
return -1;
}
needle = file_size - offset;

Return to:

Send suggestions and report system problems to the System administrator.