@@ -58,13 +58,8 @@ func vfsFind(ctx context.Context, mod api.Module, zVfsName ptr_t) uint32 {
58
58
}
59
59
60
60
func vfsLocaltime (ctx context.Context , mod api.Module , pTm ptr_t , t int64 ) _ErrorCode {
61
- tm := time .Unix (t , 0 )
62
- var isdst int32
63
- if tm .IsDST () {
64
- isdst = 1
65
- }
66
-
67
61
const size = 32 / 8
62
+ tm := time .Unix (t , 0 )
68
63
// https://pubs.opengroup.org/onlinepubs/7908799/xsh/time.h.html
69
64
util .Write32 (mod , pTm + 0 * size , int32 (tm .Second ()))
70
65
util .Write32 (mod , pTm + 1 * size , int32 (tm .Minute ()))
@@ -74,7 +69,7 @@ func vfsLocaltime(ctx context.Context, mod api.Module, pTm ptr_t, t int64) _Erro
74
69
util .Write32 (mod , pTm + 5 * size , int32 (tm .Year ()- 1900 ))
75
70
util .Write32 (mod , pTm + 6 * size , int32 (tm .Weekday ()- time .Sunday ))
76
71
util .Write32 (mod , pTm + 7 * size , int32 (tm .YearDay ()- 1 ))
77
- util .Write32 (mod , pTm + 8 * size , isdst )
72
+ util .WriteBool (mod , pTm + 8 * size , tm . IsDST () )
78
73
return _OK
79
74
}
80
75
@@ -123,11 +118,7 @@ func vfsAccess(ctx context.Context, mod api.Module, pVfs, zPath ptr_t, flags Acc
123
118
path := util .ReadString (mod , zPath , _MAX_PATHNAME )
124
119
125
120
ok , err := vfs .Access (path , flags )
126
- var res int32
127
- if ok {
128
- res = 1
129
- }
130
- util .Write32 (mod , pResOut , res )
121
+ util .WriteBool (mod , pResOut , ok )
131
122
return vfsErrorCode (err , _IOERR_ACCESS )
132
123
}
133
124
@@ -151,9 +142,8 @@ func vfsOpen(ctx context.Context, mod api.Module, pVfs, zPath, pFile ptr_t, flag
151
142
file .SetPowersafeOverwrite (b )
152
143
}
153
144
}
154
- if file , ok := file .(FileSharedMemory ); ok &&
155
- pOutVFS != 0 && file .SharedMemory () != nil {
156
- util .Write32 (mod , pOutVFS , int32 (1 ))
145
+ if file , ok := file .(FileSharedMemory ); ok && pOutVFS != 0 {
146
+ util .WriteBool (mod , pOutVFS , file .SharedMemory () != nil )
157
147
}
158
148
if pOutFlags != 0 {
159
149
util .Write32 (mod , pOutFlags , flags )
@@ -225,12 +215,7 @@ func vfsUnlock(ctx context.Context, mod api.Module, pFile ptr_t, eLock LockLevel
225
215
func vfsCheckReservedLock (ctx context.Context , mod api.Module , pFile , pResOut ptr_t ) _ErrorCode {
226
216
file := vfsFileGet (ctx , mod , pFile ).(File )
227
217
locked , err := file .CheckReservedLock ()
228
-
229
- var res int32
230
- if locked {
231
- res = 1
232
- }
233
- util .Write32 (mod , pResOut , res )
218
+ util .WriteBool (mod , pResOut , locked )
234
219
return vfsErrorCode (err , _IOERR_CHECKRESERVEDLOCK )
235
220
}
236
221
@@ -254,24 +239,20 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt
254
239
255
240
case _FCNTL_PERSIST_WAL :
256
241
if file , ok := file .(FilePersistWAL ); ok {
257
- if i := util .Read32 [int32 ](mod , pArg ); i >= 0 {
258
- file .SetPersistWAL (i != 0 )
259
- } else if file .PersistWAL () {
260
- util .Write32 (mod , pArg , int32 (1 ))
242
+ if i := util .Read32 [int32 ](mod , pArg ); i < 0 {
243
+ util .WriteBool (mod , pArg , file .PersistWAL ())
261
244
} else {
262
- util . Write32 ( mod , pArg , int32 ( 0 ) )
245
+ file . SetPersistWAL ( i != 0 )
263
246
}
264
247
return _OK
265
248
}
266
249
267
250
case _FCNTL_POWERSAFE_OVERWRITE :
268
251
if file , ok := file .(FilePowersafeOverwrite ); ok {
269
- if i := util .Read32 [int32 ](mod , pArg ); i >= 0 {
270
- file .SetPowersafeOverwrite (i != 0 )
271
- } else if file .PowersafeOverwrite () {
272
- util .Write32 (mod , pArg , int32 (1 ))
252
+ if i := util .Read32 [int32 ](mod , pArg ); i < 0 {
253
+ util .WriteBool (mod , pArg , file .PowersafeOverwrite ())
273
254
} else {
274
- util . Write32 ( mod , pArg , int32 ( 0 ) )
255
+ file . SetPowersafeOverwrite ( i != 0 )
275
256
}
276
257
return _OK
277
258
}
@@ -293,11 +274,7 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt
293
274
case _FCNTL_HAS_MOVED :
294
275
if file , ok := file .(FileHasMoved ); ok {
295
276
moved , err := file .HasMoved ()
296
- var val uint32
297
- if moved {
298
- val = 1
299
- }
300
- util .Write32 (mod , pArg , val )
277
+ util .WriteBool (mod , pArg , moved )
301
278
return vfsErrorCode (err , _IOERR_FSTAT )
302
279
}
303
280
@@ -394,7 +371,7 @@ func vfsFileControlImpl(ctx context.Context, mod api.Module, file File, op _Fcnt
394
371
case _FCNTL_LOCK_TIMEOUT :
395
372
if file , ok := file .(FileSharedMemory ); ok {
396
373
if shm , ok := file .SharedMemory ().(blockingSharedMemory ); ok {
397
- shm .shmEnableBlocking (util .Read32 [ uint32 ] (mod , pArg ) != 0 )
374
+ shm .shmEnableBlocking (util .ReadBool (mod , pArg ))
398
375
return _OK
399
376
}
400
377
}
0 commit comments