diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gdbm.h.in | 17 | ||||
-rw-r--r-- | src/gdbmopen.c | 12 | ||||
-rw-r--r-- | src/systems.h | 4 |
3 files changed, 20 insertions, 13 deletions
diff --git a/src/gdbm.h.in b/src/gdbm.h.in index 2420774..21168de 100644 --- a/src/gdbm.h.in +++ b/src/gdbm.h.in @@ -42,11 +42,12 @@ extern "C" { # define GDBM_NEWDB 3 /* A writer. Always create a new db. */ # define GDBM_OPENMASK 7 /* Mask for the above. */ -# define GDBM_FAST 0x10 /* Write fast! => No fsyncs. OBSOLETE. */ -# define GDBM_SYNC 0x20 /* Sync operations to the disk. */ -# define GDBM_NOLOCK 0x40 /* Don't do file locking operations. */ -# define GDBM_NOMMAP 0x80 /* Don't use mmap(). */ - +# define GDBM_FAST 0x010 /* Write fast! => No fsyncs. OBSOLETE. */ +# define GDBM_SYNC 0x020 /* Sync operations to the disk. */ +# define GDBM_NOLOCK 0x040 /* Don't do file locking operations. */ +# define GDBM_NOMMAP 0x080 /* Don't use mmap(). */ +# define GDBM_CLOEXEC 0x100 /* Close the underlying fd on exec(3) */ + /* Parameters to gdbm_store for simple insertion or replacement in the case that the key is already in the database. */ # define GDBM_INSERT 0 /* Never replace old data with new. */ @@ -54,7 +55,7 @@ extern "C" { /* Parameters to gdbm_setopt, specifing the type of operation to perform. */ # define GDBM_SETCACHESIZE 1 /* Set the cache size. */ -# define GDBM_FASTMODE 2 /* Toggle fast mode. OBSOLETE. */ +# define GDBM_FASTMODE 2 /* Toggle fast mode. OBSOLETE. */ # define GDBM_SETSYNCMODE 3 /* Turn on or off sync operations. */ # define GDBM_SETCENTFREE 4 /* Keep all free blocks in the header. */ # define GDBM_SETCOALESCEBLKS 5 /* Attempt to coalesce free blocks. */ @@ -64,8 +65,8 @@ extern "C" { /* Compatibility defines: */ # define GDBM_CACHESIZE GDBM_SETCACHESIZE # define GDBM_SYNCMODE GDBM_SETSYNCMODE -# define GDBM_CENTFREE GDBM_SETCENTFREE -# define GDBM_COALESCEBLKS GDBM_SETCOALESCEBLKS +# define GDBM_CENTFREE GDBM_SETCENTFREE +# define GDBM_COALESCEBLKS GDBM_SETCOALESCEBLKS # define GDBM_GETFLAGS 8 /* Get gdbm_open flags */ # define GDBM_GETMMAP 9 /* Get mmap status */ diff --git a/src/gdbmopen.c b/src/gdbmopen.c index 09eb629..9909d5e 100644 --- a/src/gdbmopen.c +++ b/src/gdbmopen.c @@ -64,6 +64,7 @@ gdbm_open (const char *file, int block_size, int flags, int mode, char need_trunc; /* Used with GDBM_NEWDB and locking to avoid truncating a file from under a reader. */ int rc; /* temporary error code */ + int fbits = 0; /* additional bits for open(2) flags */ /* Initialize the gdbm_errno variable. */ gdbm_errno = GDBM_NO_ERROR; @@ -120,26 +121,27 @@ gdbm_open (const char *file, int block_size, int flags, int mode, { dbf->file_locking = FALSE; } - + if (flags & GDBM_CLOEXEC) + fbits = O_CLOEXEC; /* Open the file. */ need_trunc = FALSE; switch (flags & GDBM_OPENMASK) { case GDBM_READER: - dbf->desc = open (dbf->name, O_RDONLY, 0); + dbf->desc = open (dbf->name, O_RDONLY|fbits, 0); break; case GDBM_WRITER: - dbf->desc = open (dbf->name, O_RDWR, 0); + dbf->desc = open (dbf->name, O_RDWR|fbits, 0); break; case GDBM_NEWDB: - dbf->desc = open (dbf->name, O_RDWR|O_CREAT, mode); + dbf->desc = open (dbf->name, O_RDWR|O_CREAT|fbits, mode); need_trunc = TRUE; break; default: - dbf->desc = open (dbf->name, O_RDWR|O_CREAT, mode); + dbf->desc = open (dbf->name, O_RDWR|O_CREAT|fbits, mode); break; } diff --git a/src/systems.h b/src/systems.h index 9a8f449..67b207e 100644 --- a/src/systems.h +++ b/src/systems.h @@ -50,6 +50,10 @@ # define L_SET SEEK_SET #endif +#ifndef O_CLOEXEC +# define O_CLOEXEC 0 +#endif + /* Default block size. Some systems do not have blocksize in their stat record. This code uses the BSD blocksize from stat. */ |