source@mandoc.bsd.lv
 help / color / mirror / Atom feed
* mdocml: In dbopen(), check success of remove("mandoc.db~").
@ 2013-06-06 15:15 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2013-06-06 15:15 UTC (permalink / raw)
  To: source

Log Message:
-----------
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.

Modified Files:
--------------
    mdocml:
        mandocdb.c

Revision Data
-------------
Index: mandocdb.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandocdb.c,v
retrieving revision 1.62
retrieving revision 1.63
diff -Lmandocdb.c -Lmandocdb.c -u -p -r1.62 -r1.63
--- mandocdb.c
+++ mandocdb.c
@@ -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) 
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2013-06-06 15:15 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-06-06 15:15 mdocml: In dbopen(), check success of remove("mandoc.db~") schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).