diff options
Diffstat (limited to 'compat')
-rw-r--r-- | compat/close.c | 12 | ||||
-rw-r--r-- | compat/dbminit.c | 72 | ||||
-rw-r--r-- | compat/fetch.c | 17 | ||||
-rw-r--r-- | compat/seq.c | 29 | ||||
-rw-r--r-- | compat/store.c | 7 |
5 files changed, 17 insertions, 120 deletions
diff --git a/compat/close.c b/compat/close.c index 1d1b13b..2b368f9 100644 --- a/compat/close.c +++ b/compat/close.c @@ -18,24 +18,18 @@ /* Include system configuration before all else. */ #include "autoconf.h" - -#include "gdbmdefs.h" -#include "extern.h" - +#include "dbm-priv.h" /* It's unclear whether dbmclose() is *always* a void function in old C libraries. We use int, here. */ int -dbmclose() +dbmclose () { if (_gdbm_file != NULL) { - gdbm_close (_gdbm_file); + dbm_close (_gdbm_file); _gdbm_file = NULL; - if (_gdbm_memory.dptr != NULL) free(_gdbm_memory.dptr); - _gdbm_memory.dptr = NULL; - _gdbm_memory.dsize = 0; } return (0); } diff --git a/compat/dbminit.c b/compat/dbminit.c index eb21292..94ddc22 100644 --- a/compat/dbminit.c +++ b/compat/dbminit.c @@ -20,9 +20,9 @@ /* Include system configuration before all else. */ #include "autoconf.h" +#include "dbm-priv.h" -#include "gdbmdefs.h" -#include "extern.h" +DBM *_gdbm_file; /* Initialize dbm system. FILE is a pointer to the file name. In standard dbm, the database is found in files called FILE.pag and @@ -37,78 +37,20 @@ int dbminit (char *file) { - 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". */ - int ret; - - - ret = 0; /* Default return value. */ - - /* Prepare the correct names of "file.pag" and "file.dir". */ - pag_file = (char *) malloc (strlen (file)+5); - dir_file = (char *) malloc (strlen (file)+5); - if ((pag_file == NULL) || (dir_file == NULL)) - { - gdbm_errno = GDBM_MALLOC_ERROR; /* For the hell of it. */ - return -1; - } - - strcpy (pag_file, file); - strcat (pag_file, ".pag"); - strcpy (dir_file, file); - strcat (dir_file, ".dir"); - if (_gdbm_file != NULL) - gdbm_close (_gdbm_file); - + dbm_close (_gdbm_file); /* Try to open the file as a writer. DBM never created a file. */ - _gdbm_file = gdbm_open (pag_file, 0, GDBM_WRITER, 0, NULL); - + _gdbm_file = dbm_open (file, O_RDWR, 0644); /* If it was not opened, try opening it as a reader. */ if (_gdbm_file == NULL) { - _gdbm_file = gdbm_open (pag_file, 0, GDBM_READER, 0, NULL); - + _gdbm_file = dbm_open (file, O_RDONLY, 0644); /* Did we successfully open the file? */ if (_gdbm_file == NULL) { gdbm_errno = GDBM_FILE_OPEN_ERROR; - ret = -1; - goto done; + return -1; } } - - /* If the database is new, link "file.dir" to "file.pag". This is done - so the time stamp on both files is the same. */ - if (stat (dir_file, &dir_stat) == 0) - { - if (dir_stat.st_size == 0) - if (unlink (dir_file) != 0 || link (pag_file, dir_file) != 0) - { - gdbm_errno = GDBM_FILE_OPEN_ERROR; - gdbm_close (_gdbm_file); - ret = -1; - goto done; - } - } - else - { - /* Since we can't stat it, we assume it is not there and try - to link the dir_file to the pag_file. */ - if (link (pag_file, dir_file) != 0) - { - gdbm_errno = GDBM_FILE_OPEN_ERROR; - gdbm_close (_gdbm_file); - ret = -1; - goto done; - } - } - - ret = 0; - -done: - free (dir_file); - free (pag_file); - return ret; + return 0; } diff --git a/compat/fetch.c b/compat/fetch.c index a0d03ae..00d369e 100644 --- a/compat/fetch.c +++ b/compat/fetch.c @@ -19,10 +19,7 @@ /* Include system configuration before all else. */ #include "autoconf.h" - -#include "gdbmdefs.h" -#include "extern.h" - +#include "dbm-priv.h" /* 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 @@ -31,15 +28,5 @@ datum fetch (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 (_gdbm_file, key); - if (_gdbm_fetch_val != NULL) free (_gdbm_fetch_val); - _gdbm_fetch_val = ret_val.dptr; - - /* Return the new value. */ - return ret_val; - + return dbm_fetch (_gdbm_file, key); } diff --git a/compat/seq.c b/compat/seq.c index f5a744f..e787f96 100644 --- a/compat/seq.c +++ b/compat/seq.c @@ -20,9 +20,7 @@ /* Include system configuration before all else. */ #include "autoconf.h" - -#include "gdbmdefs.h" -#include "extern.h" +#include "dbm-priv.h" /* Start the visit of all keys in the database. This produces something in hash order, not in any sorted order. */ @@ -30,16 +28,7 @@ datum firstkey (void) { - datum ret_val; - - /* Free previous dynamic memory, do actual call, and save pointer to new - memory. */ - ret_val = gdbm_firstkey (_gdbm_file); - if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr); - _gdbm_memory = ret_val; - - /* Return the new value. */ - return ret_val; + return dbm_firstkey (_gdbm_file); } @@ -48,17 +37,5 @@ firstkey (void) datum nextkey (datum key) { - datum ret_val; - - /* Make sure we have a valid key. */ - if (key.dptr == NULL) - return key; - - /* Call gdbm nextkey with supplied value. After that, free the old value. */ - ret_val = gdbm_nextkey (_gdbm_file, key); - if (_gdbm_memory.dptr != NULL) free (_gdbm_memory.dptr); - _gdbm_memory = ret_val; - - /* Return the new value. */ - return ret_val; + return dbm_nextkey (_gdbm_file); } diff --git a/compat/store.c b/compat/store.c index 7f21b9d..dd6ee78 100644 --- a/compat/store.c +++ b/compat/store.c @@ -19,10 +19,7 @@ /* Include system configuration before all else. */ #include "autoconf.h" - -#include "gdbmdefs.h" -#include "extern.h" - +#include "dbm-priv.h" /* 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 @@ -31,5 +28,5 @@ int store (datum key, datum content) { - return gdbm_store (_gdbm_file, key, content, GDBM_REPLACE); + return dbm_store (_gdbm_file, key, content, DBM_REPLACE); } |