From owner-svn-src-head@FreeBSD.ORG Sat Mar 28 07:09:51 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id B0AF3106564A; Sat, 28 Mar 2009 07:09:51 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 9EBF28FC16; Sat, 28 Mar 2009 07:09:51 +0000 (UTC) (envelope-from delphij@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n2S79paB087941; Sat, 28 Mar 2009 07:09:51 GMT (envelope-from delphij@svn.freebsd.org) Received: (from delphij@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n2S79pjn087940; Sat, 28 Mar 2009 07:09:51 GMT (envelope-from delphij@svn.freebsd.org) Message-Id: <200903280709.n2S79pjn087940@svn.freebsd.org> From: Xin LI Date: Sat, 28 Mar 2009 07:09:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r190495 - head/lib/libc/db/hash X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 28 Mar 2009 07:09:52 -0000 Author: delphij Date: Sat Mar 28 07:09:51 2009 New Revision: 190495 URL: http://svn.freebsd.org/changeset/base/190495 Log: 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 Modified: head/lib/libc/db/hash/hash.c Modified: head/lib/libc/db/hash/hash.c ============================================================================== --- head/lib/libc/db/hash/hash.c Sat Mar 28 06:47:05 2009 (r190494) +++ head/lib/libc/db/hash/hash.c Sat Mar 28 07:09:51 2009 (r190495) @@ -120,25 +120,15 @@ __hash_open(const char *file, int flags, */ 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);