Date: Sat, 28 Mar 2009 07:09:51 +0000 (UTC) From: Xin LI <delphij@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r190495 - head/lib/libc/db/hash Message-ID: <200903280709.n2S79pjn087940@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200903280709.n2S79pjn087940>