aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2011-08-05 11:29:42 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2011-08-05 11:29:42 +0000
commit9839c83761c573414d77de1b957bae04547bc910 (patch)
tree5698520af3c5170d3d6b971948c61899dab75d70
parent39cc2512acbcf56ffbf87e3d26afc0450ca37de9 (diff)
downloadgdbm-9839c83761c573414d77de1b957bae04547bc910.tar.gz
gdbm-9839c83761c573414d77de1b957bae04547bc910.tar.bz2
Include nbdm.h.
Use the new DBM declaration.
-rw-r--r--compat/dbmclose.c12
-rw-r--r--compat/dbmdelete.c9
-rw-r--r--compat/dbmdirfno.c7
-rw-r--r--compat/dbmfetch.c13
-rw-r--r--compat/dbmopen.c37
-rw-r--r--compat/dbmpagfno.c7
-rw-r--r--compat/dbmrdonly.c7
-rw-r--r--compat/dbmseq.c26
-rw-r--r--compat/dbmstore.c8
-rw-r--r--compat/delete.c7
10 files changed, 68 insertions, 65 deletions
diff --git a/compat/dbmclose.c b/compat/dbmclose.c
index b4114d3..1d2d31c 100644
--- a/compat/dbmclose.c
+++ b/compat/dbmclose.c
@@ -19,14 +19,18 @@
/* Include system configuration before all else. */
#include "autoconf.h"
-
+#include "ndbm.h"
#include "gdbmdefs.h"
-
/* Close the DBF file. */
void
-dbm_close (GDBM_FILE dbf)
+dbm_close (DBM *dbm)
{
- gdbm_close (dbf);
+ gdbm_close (dbm->file);
+ if (dbm->_dbm_memory.dptr)
+ free (dbm->_dbm_memory.dptr);
+ if (dbm->_dbm_fetch_val)
+ free (dbm->_dbm_fetch_val);
+ free (dbm);
}
diff --git a/compat/dbmdelete.c b/compat/dbmdelete.c
index 627e9a8..0f3f8a4 100644
--- a/compat/dbmdelete.c
+++ b/compat/dbmdelete.c
@@ -20,15 +20,12 @@
/* Include system configuration before all else. */
#include "autoconf.h"
-
-#include "gdbmdefs.h"
-#include "extern.h"
-
+#include "ndbm.h"
/* Remove the KEYed item and the KEY from the database DBF. */
int
-dbm_delete (GDBM_FILE dbf, datum key)
+dbm_delete (DBM *dbm, datum key)
{
- return gdbm_delete (dbf,key);
+ return gdbm_delete (dbm->file, key);
}
diff --git a/compat/dbmdirfno.c b/compat/dbmdirfno.c
index 20f2170..8e7f957 100644
--- a/compat/dbmdirfno.c
+++ b/compat/dbmdirfno.c
@@ -19,15 +19,14 @@
/* Include system configuration before all else. */
#include "autoconf.h"
-
+#include "ndbm.h"
#include "gdbmdefs.h"
-
/* Return the file number of the DBF file. NDBM original wanted the .dir
file number. Since we have only one file number, we return it. */
int
-dbm_dirfno (GDBM_FILE dbf)
+dbm_dirfno (DBM *dbm)
{
- return (dbf->desc);
+ return (dbm->file->desc);
}
diff --git a/compat/dbmfetch.c b/compat/dbmfetch.c
index e779d1a..03a8065 100644
--- a/compat/dbmfetch.c
+++ b/compat/dbmfetch.c
@@ -19,25 +19,24 @@
/* Include system configuration before all else. */
#include "autoconf.h"
-
+#include "ndbm.h"
#include "gdbmdefs.h"
-#include "extern.h"
-
/* NDBM Look up a given KEY and return the information associated with that
KEY. The pointer in the structure that is returned is a pointer to
dynamically allocated memory block. */
datum
-dbm_fetch (GDBM_FILE dbf, datum key)
+dbm_fetch (DBM *dbm, datum key)
{
datum ret_val; /* The return value. */
/* Free previous dynamic memory, do actual call, and save pointer to new
memory. */
- ret_val = gdbm_fetch (dbf, key);
- if (_gdbm_fetch_val != NULL) free (_gdbm_fetch_val);
- _gdbm_fetch_val = ret_val.dptr;
+ ret_val = gdbm_fetch (dbm->file, key);
+ if (dbm->_dbm_fetch_val != NULL)
+ free (dbm->_dbm_fetch_val);
+ dbm->_dbm_fetch_val = ret_val.dptr;
/* Return the new value. */
return ret_val;
diff --git a/compat/dbmopen.c b/compat/dbmopen.c
index ff2e981..83647a4 100644
--- a/compat/dbmopen.c
+++ b/compat/dbmopen.c
@@ -20,9 +20,8 @@
/* Include system configuration before all else. */
#include "autoconf.h"
-
+#include "ndbm.h"
#include "gdbmdefs.h"
-#include "extern.h"
/* Initialize ndbm system. FILE is a pointer to the file name. In
standard dbm, the database is found in files called FILE.pag and
@@ -41,13 +40,13 @@
a GDBM_NEWDB. All other values of FLAGS in the flags are
ignored. */
-GDBM_FILE
+DBM *
dbm_open (char *file, int flags, int mode)
{
char* pag_file; /* Used to construct "file.pag". */
char* dir_file; /* Used to construct "file.dir". */
struct stat dir_stat; /* Stat information for "file.dir". */
- GDBM_FILE temp_dbf; /* Temporary file pointer storage. */
+ DBM *dbm = NULL;
int open_flags;
/* Prepare the correct names of "file.pag" and "file.dir". */
@@ -62,8 +61,7 @@ dbm_open (char *file, int flags, int mode)
strcpy (pag_file, file);
strcat (pag_file, ".pag");
strcpy (dir_file, file);
- strcat (dir_file, ".dir");
-
+ strcat (dir_file, ".dir");
/* Call the actual routine, saving the pointer to the file information. */
flags &= O_RDONLY | O_RDWR | O_CREAT | O_TRUNC;
@@ -87,12 +85,23 @@ dbm_open (char *file, int flags, int mode)
mode = 0;
}
- temp_dbf = gdbm_open (pag_file, 0, open_flags | GDBM_NOLOCK, mode, NULL);
+ dbm = calloc (1, sizeof (*dbm));
+ if (!dbm)
+ {
+ free (pag_file);
+ free (dir_file);
+ gdbm_errno = GDBM_MALLOC_ERROR; /* For the hell of it. */
+ return NULL;
+ }
+
+ dbm->file = gdbm_open (pag_file, 0, open_flags | GDBM_NOLOCK, mode, NULL);
/* Did we successfully open the file? */
- if (temp_dbf == NULL)
+ if (dbm->file == NULL)
{
gdbm_errno = GDBM_FILE_OPEN_ERROR;
+ free (dbm);
+ dbm = NULL;
goto done;
}
@@ -104,8 +113,9 @@ dbm_open (char *file, int flags, int mode)
if (unlink (dir_file) != 0 || link (pag_file, dir_file) != 0)
{
gdbm_errno = GDBM_FILE_OPEN_ERROR;
- gdbm_close (temp_dbf);
- temp_dbf = NULL;
+ gdbm_close (dbm->file);
+ free (dbm);
+ dbm = NULL;
goto done;
}
}
@@ -116,8 +126,9 @@ dbm_open (char *file, int flags, int mode)
if (link (pag_file, dir_file) != 0)
{
gdbm_errno = GDBM_FILE_OPEN_ERROR;
- gdbm_close (temp_dbf);
- temp_dbf = NULL;
+ gdbm_close (dbm->file);
+ free (dbm);
+ dbm = NULL;
goto done;
}
}
@@ -125,5 +136,5 @@ dbm_open (char *file, int flags, int mode)
done:
free (pag_file);
free (dir_file);
- return temp_dbf;
+ return dbm;
}
diff --git a/compat/dbmpagfno.c b/compat/dbmpagfno.c
index b2d00ee..6e07d39 100644
--- a/compat/dbmpagfno.c
+++ b/compat/dbmpagfno.c
@@ -19,15 +19,14 @@
/* Include system configuration before all else. */
#include "autoconf.h"
-
+#include "ndbm.h"
#include "gdbmdefs.h"
-
/* Return the file number of the DBF file. NDBM original wanted the .pag
file number. Since we have only one file number, we return it. */
int
-dbm_pagfno (GDBM_FILE dbf)
+dbm_pagfno (DBM *dbm)
{
- return (dbf->desc);
+ return dbm->file->desc;
}
diff --git a/compat/dbmrdonly.c b/compat/dbmrdonly.c
index 79dbfb1..62e165f 100644
--- a/compat/dbmrdonly.c
+++ b/compat/dbmrdonly.c
@@ -18,14 +18,13 @@
/* Include system configuration before all else. */
#include "autoconf.h"
-
+#include "ndbm.h"
#include "gdbmdefs.h"
-
/* not much of a routine, but should be a function for compatibility. */
int
-dbm_rdonly(GDBM_FILE dbf)
+dbm_rdonly (DBM *dbm)
{
- return (dbf->read_write == GDBM_READER);
+ return (dbm->file->read_write == GDBM_READER);
}
diff --git a/compat/dbmseq.c b/compat/dbmseq.c
index afbb980..f98482b 100644
--- a/compat/dbmseq.c
+++ b/compat/dbmseq.c
@@ -20,25 +20,24 @@
/* Include system configuration before all else. */
#include "autoconf.h"
-
+#include "ndbm.h"
#include "gdbmdefs.h"
-#include "extern.h"
-
/* NDBM Start the visit of all keys in the database. This produces
something in hash order, not in any sorted order. DBF is the dbm file
information pointer. */
datum
-dbm_firstkey (GDBM_FILE dbf)
+dbm_firstkey (DBM *dbm)
{
datum ret_val;
/* Free previous dynamic memory, do actual call, and save pointer to new
memory. */
- ret_val = gdbm_firstkey (dbf);
- if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
- _gdbm_memory = ret_val;
+ ret_val = gdbm_firstkey (dbm->file);
+ if (dbm->_dbm_memory.dptr != NULL)
+ free (dbm->_dbm_memory.dptr);
+ dbm->_dbm_memory = ret_val;
/* Return the new value. */
return ret_val;
@@ -49,18 +48,19 @@ dbm_firstkey (GDBM_FILE dbf)
DBF is the file information pointer. */
datum
-dbm_nextkey (GDBM_FILE dbf)
+dbm_nextkey (DBM *dbm)
{
datum ret_val;
/* Make sure we have a valid key. */
- if (_gdbm_memory.dptr == NULL)
- return _gdbm_memory;
+ if (dbm->_dbm_memory.dptr == NULL)
+ return dbm->_dbm_memory;
/* Call gdbm nextkey with the old value. After that, free the old value. */
- ret_val = gdbm_nextkey (dbf,_gdbm_memory);
- if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr);
- _gdbm_memory = ret_val;
+ ret_val = gdbm_nextkey (dbm->file, dbm->_dbm_memory);
+ if (dbm->_dbm_memory.dptr != NULL)
+ free (dbm->_dbm_memory.dptr);
+ dbm->_dbm_memory = ret_val;
/* Return the new value. */
return ret_val;
diff --git a/compat/dbmstore.c b/compat/dbmstore.c
index b07bbdc..1b6636a 100644
--- a/compat/dbmstore.c
+++ b/compat/dbmstore.c
@@ -19,17 +19,15 @@
/* Include system configuration before all else. */
#include "autoconf.h"
-
+#include "ndbm.h"
#include "gdbmdefs.h"
-#include "extern.h"
-
/* NDBM add a new element to the database. CONTENT is keyed by KEY.
The file on disk is updated to reflect the structure of the new
database before returning from this procedure. */
int
-dbm_store (GDBM_FILE dbf, datum key, datum content, int flags)
+dbm_store (DBM *dbm, datum key, datum content, int flags)
{
- return gdbm_store (dbf, key, content, flags);
+ return gdbm_store (dbm->file, key, content, flags);
}
diff --git a/compat/delete.c b/compat/delete.c
index a40e173..a267dcc 100644
--- a/compat/delete.c
+++ b/compat/delete.c
@@ -20,15 +20,12 @@
/* Include system configuration before all else. */
#include "autoconf.h"
-
-#include "gdbmdefs.h"
-#include "extern.h"
-
+#include "dbm-priv.h"
/* Remove the KEYed item and the KEY from the database. */
int
delete (datum key)
{
- return gdbm_delete (_gdbm_file, key);
+ return dbm_delete (_gdbm_file, key);
}

Return to:

Send suggestions and report system problems to the System administrator.