aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-08-05 12:50:52 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-08-05 12:50:52 +0000
commit99660883f075bacb16d7284523a36f8e6c69a665 (patch)
tree424e175eb4f2af8a990f03bc597bc819f6642bec
parent3269dd3e704bc9880455b95bb67a490b5b503216 (diff)
downloadmandoc-99660883f075bacb16d7284523a36f8e6c69a665.tar.gz
mandoc-99660883f075bacb16d7284523a36f8e6c69a665.tar.zst
mandoc-99660883f075bacb16d7284523a36f8e6c69a665.zip
Since old SQLite versions do not have sqlite3_errstr(),
provide a dummy fallback implementation. Do not bother to decode the error, SQLite error codes are not useful enough for that to be worthwhile. Note that using sqlite3_errmsg(db) would be a bad idea: On malloc() failure, db is NULL, which would cause a segfault. Issue noticed by kristaps@.
-rw-r--r--Makefile5
-rw-r--r--compat_sqlite3_errstr.c18
-rw-r--r--config.h.post3
-rwxr-xr-xconfigure2
-rw-r--r--test-sqlite3_errstr.c8
5 files changed, 35 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index bedbda46..748f40f0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-# $Id: Makefile,v 1.431 2014/08/05 11:19:13 schwarze Exp $
+# $Id: Makefile,v 1.432 2014/08/05 12:50:52 schwarze Exp $
#
# Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
# Copyright (c) 2011, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -121,6 +121,7 @@ TESTSRCS = test-fgetln.c \
test-mmap.c \
test-ohash.c \
test-reallocarray.c \
+ test-sqlite3_errstr.c \
test-strcasestr.c \
test-strlcat.c \
test-strlcpy.c \
@@ -136,6 +137,7 @@ SRCS = apropos.c \
compat_getsubopt.c \
compat_ohash.c \
compat_reallocarray.c \
+ compat_sqlite3_errstr.c \
compat_strcasestr.c \
compat_strlcat.c \
compat_strlcpy.c \
@@ -281,6 +283,7 @@ COMPAT_OBJS = compat_fgetln.o \
compat_getsubopt.o \
compat_ohash.o \
compat_reallocarray.o \
+ compat_sqlite3_errstr.o \
compat_strcasestr.o \
compat_strlcat.o \
compat_strlcpy.o \
diff --git a/compat_sqlite3_errstr.c b/compat_sqlite3_errstr.c
new file mode 100644
index 00000000..b8d6eb58
--- /dev/null
+++ b/compat_sqlite3_errstr.c
@@ -0,0 +1,18 @@
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#ifdef HAVE_SQLITE3_ERRSTR
+
+int dummy;
+
+#else
+
+const char *
+sqlite3_errstr(int rc)
+{
+
+ return(rc ? "unknown error" : "not an error");
+}
+
+#endif
diff --git a/config.h.post b/config.h.post
index 07b53415..e95f5f53 100644
--- a/config.h.post
+++ b/config.h.post
@@ -23,6 +23,9 @@ extern char *suboptarg;
#ifndef HAVE_REALLOCARRAY
extern void *reallocarray(void *, size_t, size_t);
#endif
+#ifndef HAVE_SQLITE3_ERRSTR
+extern const char *sqlite3_errstr(int);
+#endif
#ifndef HAVE_STRCASESTR
extern char *strcasestr(const char *, const char *);
#endif
diff --git a/configure b/configure
index 0fd937f8..991c7669 100755
--- a/configure
+++ b/configure
@@ -35,6 +35,8 @@ runtest getsubopt GETSUBOPT
runtest mmap MMAP
runtest ohash OHASH -lutil
runtest reallocarray REALLOCARRAY
+runtest sqlite3_errstr SQLITE3_ERRSTR \
+ "-I/usr/local/include -L/usr/local/lib -lsqlite3"
runtest strcasestr STRCASESTR
runtest strlcat STRLCAT
runtest strlcpy STRLCPY
diff --git a/test-sqlite3_errstr.c b/test-sqlite3_errstr.c
new file mode 100644
index 00000000..041bf628
--- /dev/null
+++ b/test-sqlite3_errstr.c
@@ -0,0 +1,8 @@
+#include <string.h>
+#include <sqlite3.h>
+
+int
+main(void)
+{
+ return(strcmp(sqlite3_errstr(SQLITE_OK), "not an error"));
+}