summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorpst <pst@FreeBSD.org>1996-02-25 04:50:21 +0000
committerpst <pst@FreeBSD.org>1996-02-25 04:50:21 +0000
commit73fc8e0896acd2776c160bb9fa924a472f7de656 (patch)
tree4f166075b2b3c8c741fc17de715389f7b1c4dd92 /lib
parentfa277022da80c9662ca1f71008237cedffb02b81 (diff)
downloadFreeBSD-src-73fc8e0896acd2776c160bb9fa924a472f7de656.zip
FreeBSD-src-73fc8e0896acd2776c160bb9fa924a472f7de656.tar.gz
move stat behind open to cover corner case
Diffstat (limited to 'lib')
-rw-r--r--lib/libc/db/hash/hash.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/libc/db/hash/hash.c b/lib/libc/db/hash/hash.c
index ea6ff47..d2707cd 100644
--- a/lib/libc/db/hash/hash.c
+++ b/lib/libc/db/hash/hash.c
@@ -122,8 +122,7 @@ __hash_open(file, flags, mode, info, dflags)
new_table = 0;
if (!file || (flags & O_TRUNC) ||
- (stat(file, &statbuf) && (errno == ENOENT)) ||
- statbuf.st_size == 0) {
+ (stat(file, &statbuf) && (errno == ENOENT))) {
if (errno == ENOENT)
errno = 0; /* Just in case someone looks at errno */
new_table = 1;
@@ -131,6 +130,13 @@ __hash_open(file, flags, mode, info, dflags)
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);
}
if (new_table) {
OpenPOWER on IntegriCloud