From 73fc8e0896acd2776c160bb9fa924a472f7de656 Mon Sep 17 00:00:00 2001 From: pst Date: Sun, 25 Feb 1996 04:50:21 +0000 Subject: move stat behind open to cover corner case --- lib/libc/db/hash/hash.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'lib') 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) { -- cgit v1.1