aboutsummaryrefslogtreecommitdiff
path: root/ext/misc/fileio.c
diff options
context:
space:
mode:
authorlarrybr <larrybr@noemail.net>2021-09-20 20:15:28 +0000
committerlarrybr <larrybr@noemail.net>2021-09-20 20:15:28 +0000
commit3d9974342345fc159b0053e0a51adb48f6366e23 (patch)
tree6c7a08b705e350a75ad1a7e5fd616e694fa20803 /ext/misc/fileio.c
parent5488e0827a89699e35c0cfc75111f275e003d5df (diff)
downloadsqlite-3d9974342345fc159b0053e0a51adb48f6366e23.tar.gz
sqlite-3d9974342345fc159b0053e0a51adb48f6366e23.zip
Allow fileio extension to be a stand-alone DLL for Win32
FossilOrigin-Name: d1cc3105b2baceb9f426fd6bc8d8317de3af09a0f02517715bd292c68e282fa1
Diffstat (limited to 'ext/misc/fileio.c')
-rw-r--r--ext/misc/fileio.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/ext/misc/fileio.c b/ext/misc/fileio.c
index d977d41dd..deb714cee 100644
--- a/ext/misc/fileio.c
+++ b/ext/misc/fileio.c
@@ -72,6 +72,11 @@
** $path is a relative path, then $path is interpreted relative to $dir.
** And the paths returned in the "name" column of the table are also
** relative to directory $dir.
+**
+** Notes on building this extension for Windows:
+** Unless linked statically with the SQLite library, a preprocessor
+** symbol, FILEIO_WIN32_DLL, must be #define'd to create a stand-alone
+** DLL form of this extension for WIN32. See its use below for details.
*/
#include "sqlite3ext.h"
SQLITE_EXTENSION_INIT1
@@ -225,6 +230,22 @@ static sqlite3_uint64 fileTimeToUnixTime(
return (fileIntervals.QuadPart - epochIntervals.QuadPart) / 10000000;
}
+
+#if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
+# /* To allow a standalone DLL, use this next replacement function: */
+# undef sqlite3_win32_utf8_to_unicode
+# define sqlite3_win32_utf8_to_unicode utf8_to_utf16
+#
+LPWSTR utf8_to_utf16(const char *z){
+ int nAllot = MultiByteToWideChar(CP_UTF8, 0, z, -1, NULL, 0);
+ LPWSTR rv = malloc(nAllot * sizeof(WCHAR));
+ if( rv!=0 && 0 < MultiByteToWideChar(CP_UTF8, 0, z, -1, rv, nAllot) )
+ return rv;
+ free(rv);
+ return 0;
+}
+#endif
+
/*
** This function attempts to normalize the time values found in the stat()
** buffer to UTC. This is necessary on Win32, where the runtime library
@@ -998,3 +1019,17 @@ int sqlite3_fileio_init(
}
return rc;
}
+
+#if defined(FILEIO_WIN32_DLL) && (defined(_WIN32) || defined(WIN32))
+ /* To allow a standalone DLL, make test_windirent.c take these next
+ * 3 functions from C runtime instead of from SQLite library: */
+# undef sqlite3_malloc
+# define sqlite3_malloc malloc
+# undef sqlite3_free
+# define sqlite3_free free
+# undef sqlite3_stricmp
+# define sqlite3_stricmp stricmp
+ /* Just pull in this .c so above redefines take said effect. As a
+ * side-effect, this extension becomes a single translation unit. */
+# include "test_windirent.c"
+#endif