aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/mandocdb.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2013-06-06 15:15:07 +0000
committerIngo Schwarze <schwarze@openbsd.org>2013-06-06 15:15:07 +0000
commite57826a67fe010b43faaeb1f84e6c4def1a10e17 (patch)
tree2fb71e62891cf130293bb9bda510f9f25f0f6c09 /mandocdb.c
parent06c5aa8bd50129b600b1f47360322e6357a10d51 (diff)
downloadmandoc-e57826a67fe010b43faaeb1f84e6c4def1a10e17.tar.gz
mandoc-e57826a67fe010b43faaeb1f84e6c4def1a10e17.tar.zst
mandoc-e57826a67fe010b43faaeb1f84e6c4def1a10e17.zip
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.
Diffstat (limited to 'mandocdb.c')
-rw-r--r--mandocdb.c37
1 files changed, 15 insertions, 22 deletions
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 <kristaps@bsd.lv>
* Copyright (c) 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
@@ -23,6 +23,7 @@
#include <assert.h>
#include <ctype.h>
+#include <errno.h>
#include <fcntl.h>
#include <fts.h>
#include <getopt.h>
@@ -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)