aboutsummaryrefslogtreecommitdiff
path: root/lib/libc/db
diff options
context:
space:
mode:
authorXin LI <delphij@FreeBSD.org>2009-03-28 07:09:51 +0000
committerXin LI <delphij@FreeBSD.org>2009-03-28 07:09:51 +0000
commitedcdc752ecddf8f0065064d63795ed85aa8d4a9e (patch)
treeb4c6bbf80b2c06d69f3a9c66f3c7f8a47b35477e /lib/libc/db
parenta47fc8251914c0f596ede58b494a39d50f5997eb (diff)
downloadsrc-edcdc752ecddf8f0065064d63795ed85aa8d4a9e.tar.gz
src-edcdc752ecddf8f0065064d63795ed85aa8d4a9e.zip
Simplify the logic when determining whether to zero out a db file to after
open(). The previous logic only initializes the database when O_CREAT is set, but as long as we can open and write the database, and the database is empty, we should initialize it anyway. Obtained from: OpenBSD
Notes
Notes: svn path=/head/; revision=190495
Diffstat (limited to 'lib/libc/db')
-rw-r--r--lib/libc/db/hash/hash.c20
1 files changed, 5 insertions, 15 deletions
diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c
index e33318566983..dda70f837f4f 100644
--- a/lib/libc/db/hash/hash.c
+++ b/lib/libc/db/hash/hash.c
@@ -120,25 +120,15 @@ __hash_open(const char *file, int flags, int mode,
*/
hashp->flags = flags;
- new_table = 0;
- if (!file || (flags & O_TRUNC) ||
- (stat(file, &statbuf) && (errno == ENOENT))) {
- if (errno == ENOENT)
- errno = 0; /* Just in case someone looks at errno */
- new_table = 1;
- }
if (file) {
if ((hashp->fp = _open(file, flags, mode)) == -1)
RETURN_ERROR(errno, error0);
-
- /* if the .db file is empty, and we had permission to create
- a new .db file, then reinitialize the database */
- if ((flags & O_CREAT) &&
- _fstat(hashp->fp, &statbuf) == 0 && statbuf.st_size == 0)
- new_table = 1;
-
(void)_fcntl(hashp->fp, F_SETFD, 1);
- }
+ new_table = _fstat(hashp->fp, &statbuf) == 0 &&
+ statbuf.st_size == 0 && (flags & O_ACCMODE) != O_RDONLY;
+ } else
+ new_table = 1;
+
if (new_table) {
if (!(hashp = init_hash(hashp, file, info)))
RETURN_ERROR(errno, error1);