6
6
7
7
// sqlite3_io_methods javascript handlers
8
8
// 64-bit integer parameters are passed by pointer.
9
- extern int vfsClose (sqlite3_file * file );
10
- extern int vfsRead (sqlite3_file * file , void * pData , int iAmt , sqlite3_int64 iOffset );
11
- extern int vfsWrite (sqlite3_file * file , const void * pData , int iAmt , sqlite3_int64 iOffset );
12
- extern int vfsTruncate (sqlite3_file * file , sqlite3_int64 size );
13
- extern int vfsSync (sqlite3_file * file , int flags );
14
- extern int vfsFileSize (sqlite3_file * file , sqlite3_int64 * pSize );
15
- extern int vfsLock (sqlite3_file * file , int flags );
16
- extern int vfsUnlock (sqlite3_file * file , int flags );
17
- extern int vfsCheckReservedLock (sqlite3_file * file , int * pResOut );
18
- extern int vfsFileControl (sqlite3_file * file , int flags , void * pOut );
19
- extern int vfsSectorSize (sqlite3_file * file );
20
- extern int vfsDeviceCharacteristics (sqlite3_file * file );
9
+ extern int vfsClose (sqlite3_file * file );
10
+ extern int vfsRead (sqlite3_file * file , void * pData , int iAmt , sqlite3_int64 iOffset );
11
+ extern int vfsWrite (sqlite3_file * file , const void * pData , int iAmt , sqlite3_int64 iOffset );
12
+ extern int vfsTruncate (sqlite3_file * file , sqlite3_int64 size );
13
+ extern int vfsSync (sqlite3_file * file , int flags );
14
+ extern int vfsFileSize (sqlite3_file * file , sqlite3_int64 * pSize );
15
+ extern int vfsLock (sqlite3_file * file , int flags );
16
+ extern int vfsUnlock (sqlite3_file * file , int flags );
17
+ extern int vfsCheckReservedLock (sqlite3_file * file , int * pResOut );
18
+ extern int vfsFileControl (sqlite3_file * file , int flags , void * pOut );
19
+ extern int vfsSectorSize (sqlite3_file * file );
20
+ extern int vfsDeviceCharacteristics (sqlite3_file * file );
21
21
22
- extern int vfsOpen (sqlite3_vfs * vfs , const char * zName , sqlite3_file * file , int flags , int * pOutFlags );
23
- extern int vfsDelete (sqlite3_vfs * vfs , const char * zName , int syncDir );
24
- extern int vfsAccess (sqlite3_vfs * vfs , const char * zName , int flags , int * pResOut );
22
+ extern int vfsOpen (sqlite3_vfs * vfs , const char * zName , sqlite3_file * file , int flags , int * pOutFlags );
23
+ extern int vfsDelete (sqlite3_vfs * vfs , const char * zName , int syncDir );
24
+ extern int vfsAccess (sqlite3_vfs * vfs , const char * zName , int flags , int * pResOut );
25
25
26
26
// This is undefined in the WASM linker step if not specified
27
27
extern int __rust_no_alloc_shim_is_unstable = 0 ;
28
28
extern int sqlite3_powersync_init (sqlite3 * db , char * * pzErrMsg ,
29
- const sqlite3_api_routines * pApi );
29
+ const sqlite3_api_routines * pApi );
30
30
31
- static int xOpen (sqlite3_vfs * vfs , const char * zName , sqlite3_file * file , int flags , int * pOutFlags ) {
31
+ static int xOpen (sqlite3_vfs * vfs , const char * zName , sqlite3_file * file , int flags , int * pOutFlags )
32
+ {
32
33
static sqlite3_io_methods io_methods = {
33
- 1 ,
34
- vfsClose ,
35
- vfsRead ,
36
- vfsWrite ,
37
- vfsTruncate ,
38
- vfsSync ,
39
- vfsFileSize ,
40
- vfsLock ,
41
- vfsUnlock ,
42
- vfsCheckReservedLock ,
43
- vfsFileControl ,
44
- vfsSectorSize ,
45
- vfsDeviceCharacteristics
46
- };
34
+ 1 ,
35
+ vfsClose ,
36
+ vfsRead ,
37
+ vfsWrite ,
38
+ vfsTruncate ,
39
+ vfsSync ,
40
+ vfsFileSize ,
41
+ vfsLock ,
42
+ vfsUnlock ,
43
+ vfsCheckReservedLock ,
44
+ vfsFileControl ,
45
+ vfsSectorSize ,
46
+ vfsDeviceCharacteristics };
47
47
file -> pMethods = & io_methods ;
48
48
49
49
return vfsOpen (vfs , zName , file , flags , pOutFlags );
50
50
}
51
51
52
- static int xFullPathname (sqlite3_vfs * vfs , const char * zName , int nOut , char * zOut ) {
52
+ static int xFullPathname (sqlite3_vfs * vfs , const char * zName , int nOut , char * zOut )
53
+ {
53
54
strncpy (zOut , zName , nOut );
54
55
return SQLITE_OK ;
55
56
}
56
57
57
- static int xCurrentTime (sqlite3_vfs * vfs , double * pJulianDay ) {
58
+ static int xCurrentTime (sqlite3_vfs * vfs , double * pJulianDay )
59
+ {
58
60
// UNIX epoch 1/1/1970 is Julian day 2440587.5
59
- static const sqlite3_int64 unixEpoch = 24405875 * (sqlite3_int64 )8640000 ;
61
+ static const sqlite3_int64 unixEpoch = 24405875 * (sqlite3_int64 )8640000 ;
60
62
struct timeval sNow ;
61
63
gettimeofday (& sNow , 0 );
62
- sqlite3_int64 julianMillis = unixEpoch + 1000 * (sqlite3_int64 )sNow .tv_sec + sNow .tv_usec / 1000 ;
64
+ sqlite3_int64 julianMillis = unixEpoch + 1000 * (sqlite3_int64 )sNow .tv_sec + sNow .tv_usec / 1000 ;
63
65
* pJulianDay = julianMillis / 86400000.0 ;
64
66
return SQLITE_OK ;
65
67
}
66
68
67
69
const int EMSCRIPTEN_KEEPALIVE register_vfs (
68
- const char * zName ,
69
- int mxPathName ,
70
- int makeDefault ,
71
- sqlite3_vfs * * ppVFS ) {
72
- sqlite3_vfs * vfs = * ppVFS = (sqlite3_vfs * )sqlite3_malloc (sizeof (sqlite3_vfs ));
73
- if (!vfs ) {
70
+ const char * zName ,
71
+ int mxPathName ,
72
+ int makeDefault ,
73
+ sqlite3_vfs * * ppVFS )
74
+ {
75
+ sqlite3_vfs * vfs = * ppVFS = (sqlite3_vfs * )sqlite3_malloc (sizeof (sqlite3_vfs ));
76
+ if (!vfs )
77
+ {
74
78
return SQLITE_NOMEM ;
75
79
}
76
80
@@ -85,9 +89,9 @@ const int EMSCRIPTEN_KEEPALIVE register_vfs(
85
89
vfs -> xAccess = vfsAccess ;
86
90
vfs -> xFullPathname = xFullPathname ;
87
91
vfs -> xCurrentTime = xCurrentTime ;
88
-
92
+
89
93
// Get remaining functionality from the default VFS.
90
- sqlite3_vfs * defer = sqlite3_vfs_find (0 );
94
+ sqlite3_vfs * defer = sqlite3_vfs_find (0 );
91
95
#define COPY_FIELD (NAME ) vfs->NAME = defer->NAME
92
96
COPY_FIELD (xDlOpen );
93
97
COPY_FIELD (xDlError );
@@ -99,22 +103,26 @@ const int EMSCRIPTEN_KEEPALIVE register_vfs(
99
103
#undef COPY_FIELD
100
104
101
105
const int result = sqlite3_vfs_register (vfs , makeDefault );
102
- if (result != SQLITE_OK ) {
106
+ if (result != SQLITE_OK )
107
+ {
103
108
* ppVFS = 0 ;
104
109
sqlite3_free (vfs );
105
110
}
106
111
return result ;
107
112
}
108
113
109
- void * EMSCRIPTEN_KEEPALIVE getSqliteFree () {
114
+ void * EMSCRIPTEN_KEEPALIVE getSqliteFree ()
115
+ {
110
116
return sqlite3_free ;
111
117
}
112
118
113
- int main () {
119
+ int main ()
120
+ {
114
121
sqlite3_initialize ();
115
122
return 0 ;
116
123
}
117
124
118
- int setup_powersync () {
119
- return sqlite3_auto_extension ((void (* )(void )) & sqlite3_powersync_init );
125
+ int setup_powersync ()
126
+ {
127
+ return sqlite3_auto_extension ((void (* )(void )) & sqlite3_powersync_init );
120
128
}
0 commit comments