From e57826a67fe010b43faaeb1f84e6c4def1a10e17 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Thu, 6 Jun 2013 15:15:07 +0000 Subject: In dbopen(), check success of remove("mandoc.db~"). While here, simplify dbopen() and dbclose(): No need for strlcpy() and strlcat() when dealing with constant strings only. --- mandocdb.c | 37 +++++++++++++++---------------------- 1 file changed, 15 insertions(+), 22 deletions(-) (limited to 'mandocdb.c') diff --git a/mandocdb.c b/mandocdb.c index ead0749a..1829f4b9 100644 --- a/mandocdb.c +++ b/mandocdb.c @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.62 2013/06/06 02:40:37 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.63 2013/06/06 15:15:07 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2013 Ingo Schwarze @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -1864,7 +1865,6 @@ static void dbclose(int real) { size_t i; - char file[PATH_MAX]; if (nodb) return; @@ -1880,9 +1880,7 @@ dbclose(int real) if (real) return; - strlcpy(file, MANDOC_DB, PATH_MAX); - strlcat(file, "~", PATH_MAX); - if (-1 == rename(file, MANDOC_DB)) { + if (-1 == rename(MANDOC_DB "~", MANDOC_DB)) { exitcode = (int)MANDOCLEVEL_SYSERR; say(MANDOC_DB, NULL); } @@ -1899,28 +1897,23 @@ dbclose(int real) static int dbopen(int real) { - char file[PATH_MAX]; - const char *sql; + const char *file, *sql; int rc, ofl; - size_t sz; if (nodb) return(1); - sz = strlcpy(file, MANDOC_DB, PATH_MAX); - if ( ! real) - sz = strlcat(file, "~", PATH_MAX); - - if (sz >= PATH_MAX) { - fprintf(stderr, "%s: Path too long\n", file); - return(0); - } - - if ( ! real) - remove(file); - - ofl = SQLITE_OPEN_READWRITE | - (0 == real ? SQLITE_OPEN_EXCLUSIVE : 0); + ofl = SQLITE_OPEN_READWRITE; + if (0 == real) { + file = MANDOC_DB "~"; + if (-1 == remove(file) && ENOENT != errno) { + exitcode = (int)MANDOCLEVEL_SYSERR; + say(file, NULL); + return(0); + } + ofl |= SQLITE_OPEN_EXCLUSIVE; + } else + file = MANDOC_DB; rc = sqlite3_open_v2(file, &db, ofl, NULL); if (SQLITE_OK == rc) -- cgit v1.2.3-56-ge451