@grain/stdlib 0.4.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +73 -0
- package/array.gr +18 -18
- package/array.md +18 -18
- package/bigint.gr +497 -0
- package/bigint.md +811 -0
- package/buffer.gr +49 -213
- package/buffer.md +24 -17
- package/bytes.gr +100 -202
- package/bytes.md +19 -0
- package/char.gr +63 -133
- package/exception.md +6 -0
- package/float32.gr +39 -78
- package/float64.gr +43 -78
- package/hash.gr +37 -37
- package/int32.gr +152 -198
- package/int32.md +104 -0
- package/int64.gr +151 -197
- package/int64.md +104 -0
- package/list.gr +467 -70
- package/list.md +1141 -0
- package/map.gr +192 -7
- package/map.md +525 -0
- package/number.gr +30 -54
- package/number.md +3 -3
- package/option.md +1 -1
- package/package.json +3 -3
- package/pervasives.gr +499 -59
- package/pervasives.md +1116 -0
- package/queue.gr +4 -0
- package/queue.md +10 -0
- package/random.gr +196 -0
- package/random.md +179 -0
- package/regex.gr +1833 -842
- package/regex.md +11 -11
- package/result.md +1 -1
- package/runtime/bigint.gr +2045 -0
- package/runtime/bigint.md +326 -0
- package/runtime/dataStructures.gr +99 -278
- package/runtime/dataStructures.md +391 -0
- package/runtime/debug.md +6 -0
- package/runtime/equal.gr +5 -23
- package/runtime/equal.md +6 -0
- package/runtime/exception.md +30 -0
- package/runtime/gc.gr +20 -3
- package/runtime/gc.md +36 -0
- package/runtime/malloc.gr +13 -11
- package/runtime/malloc.md +55 -0
- package/runtime/numberUtils.gr +91 -41
- package/runtime/numberUtils.md +54 -0
- package/runtime/numbers.gr +1043 -391
- package/runtime/numbers.md +300 -0
- package/runtime/string.gr +136 -230
- package/runtime/string.md +24 -0
- package/runtime/stringUtils.gr +58 -38
- package/runtime/stringUtils.md +6 -0
- package/runtime/unsafe/constants.gr +17 -0
- package/runtime/unsafe/constants.md +72 -0
- package/runtime/unsafe/conv.md +71 -0
- package/runtime/unsafe/errors.md +204 -0
- package/runtime/unsafe/memory.md +54 -0
- package/runtime/unsafe/printWasm.md +24 -0
- package/runtime/unsafe/tags.gr +9 -8
- package/runtime/unsafe/tags.md +120 -0
- package/runtime/unsafe/wasmf32.md +168 -0
- package/runtime/unsafe/wasmf64.md +168 -0
- package/runtime/unsafe/wasmi32.md +282 -0
- package/runtime/unsafe/wasmi64.md +300 -0
- package/runtime/utils/printing.gr +62 -0
- package/runtime/utils/printing.md +18 -0
- package/runtime/wasi.gr +1 -1
- package/runtime/wasi.md +839 -0
- package/set.gr +17 -8
- package/set.md +24 -21
- package/stack.gr +3 -3
- package/stack.md +4 -6
- package/string.gr +194 -329
- package/string.md +3 -3
- package/sys/file.gr +245 -429
- package/sys/process.gr +27 -45
- package/sys/random.gr +47 -16
- package/sys/random.md +38 -0
- package/sys/time.gr +11 -27
package/sys/file.gr
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* grainc-flags --no-gc */
|
|
2
1
|
/**
|
|
3
2
|
* @module Sys/File: Utilities for accessing the filesystem & working with files.
|
|
4
3
|
*
|
|
@@ -30,7 +29,6 @@ import {
|
|
|
30
29
|
tagSimpleNumber,
|
|
31
30
|
allocateArray,
|
|
32
31
|
allocateString,
|
|
33
|
-
loadAdtVal,
|
|
34
32
|
newInt64,
|
|
35
33
|
allocateInt64,
|
|
36
34
|
} from "runtime/dataStructures"
|
|
@@ -57,6 +55,7 @@ export enum LookupFlag {
|
|
|
57
55
|
}
|
|
58
56
|
|
|
59
57
|
// TODO(#775): This has specific ordering requirements because of ambiguous type inference
|
|
58
|
+
@unsafe
|
|
60
59
|
let rec combineLookupFlagsHelp = (acc, dirflags) => {
|
|
61
60
|
match (dirflags) {
|
|
62
61
|
[hd, ...tl] => {
|
|
@@ -68,6 +67,7 @@ let rec combineLookupFlagsHelp = (acc, dirflags) => {
|
|
|
68
67
|
[] => acc,
|
|
69
68
|
}
|
|
70
69
|
}
|
|
70
|
+
@unsafe
|
|
71
71
|
let combineLookupFlags = dirflags => {
|
|
72
72
|
combineLookupFlagsHelp(0n, dirflags)
|
|
73
73
|
}
|
|
@@ -87,6 +87,7 @@ export enum OpenFlag {
|
|
|
87
87
|
}
|
|
88
88
|
|
|
89
89
|
// TODO(#775): This has specific ordering requirements because of ambiguous type inference
|
|
90
|
+
@unsafe
|
|
90
91
|
let rec combineOpenFlagsHelp = (acc, dirflags) => {
|
|
91
92
|
match (dirflags) {
|
|
92
93
|
[hd, ...tl] => {
|
|
@@ -101,6 +102,7 @@ let rec combineOpenFlagsHelp = (acc, dirflags) => {
|
|
|
101
102
|
[] => acc,
|
|
102
103
|
}
|
|
103
104
|
}
|
|
105
|
+
@unsafe
|
|
104
106
|
let combineOpenFlags = dirflags => {
|
|
105
107
|
combineOpenFlagsHelp(0n, dirflags)
|
|
106
108
|
}
|
|
@@ -184,37 +186,67 @@ export enum Rights {
|
|
|
184
186
|
|
|
185
187
|
// Grain currently cannot close over unsafe wasm i64s, so these are here in
|
|
186
188
|
// module so they get inlined
|
|
189
|
+
@unsafe
|
|
187
190
|
let _RIGHT_FD_DATASYNC = 1N
|
|
191
|
+
@unsafe
|
|
188
192
|
let _RIGHT_FD_READ = 2N
|
|
193
|
+
@unsafe
|
|
189
194
|
let _RIGHT_FD_SEEK = 4N
|
|
195
|
+
@unsafe
|
|
190
196
|
let _RIGHT_FD_FDSTAT_SET_FLAGS = 8N
|
|
197
|
+
@unsafe
|
|
191
198
|
let _RIGHT_FD_SYNC = 16N
|
|
199
|
+
@unsafe
|
|
192
200
|
let _RIGHT_FD_TELL = 32N
|
|
201
|
+
@unsafe
|
|
193
202
|
let _RIGHT_FD_WRITE = 64N
|
|
203
|
+
@unsafe
|
|
194
204
|
let _RIGHT_FD_ADVISE = 128N
|
|
205
|
+
@unsafe
|
|
195
206
|
let _RIGHT_FD_ALLOCATE = 256N
|
|
207
|
+
@unsafe
|
|
196
208
|
let _RIGHT_PATH_CREATE_DIRECTORY = 512N
|
|
209
|
+
@unsafe
|
|
197
210
|
let _RIGHT_PATH_CREATE_FILE = 1024N
|
|
211
|
+
@unsafe
|
|
198
212
|
let _RIGHT_PATH_LINK_SOURCE = 2048N
|
|
213
|
+
@unsafe
|
|
199
214
|
let _RIGHT_PATH_LINK_TARGET = 4096N
|
|
215
|
+
@unsafe
|
|
200
216
|
let _RIGHT_PATH_OPEN = 8192N
|
|
217
|
+
@unsafe
|
|
201
218
|
let _RIGHT_FD_READDIR = 16384N
|
|
219
|
+
@unsafe
|
|
202
220
|
let _RIGHT_PATH_READLINK = 32768N
|
|
221
|
+
@unsafe
|
|
203
222
|
let _RIGHT_PATH_RENAME_SOURCE = 65536N
|
|
223
|
+
@unsafe
|
|
204
224
|
let _RIGHT_PATH_RENAME_TARGET = 131072N
|
|
225
|
+
@unsafe
|
|
205
226
|
let _RIGHT_PATH_FILESTAT_GET = 262144N
|
|
227
|
+
@unsafe
|
|
206
228
|
let _RIGHT_PATH_FILESTAT_SET_SIZE = 524288N
|
|
229
|
+
@unsafe
|
|
207
230
|
let _RIGHT_PATH_FILESTAT_SET_TIMES = 1048576N
|
|
231
|
+
@unsafe
|
|
208
232
|
let _RIGHT_FD_FILESTAT_GET = 2097152N
|
|
233
|
+
@unsafe
|
|
209
234
|
let _RIGHT_FD_FILESTAT_SET_SIZE = 4194304N
|
|
235
|
+
@unsafe
|
|
210
236
|
let _RIGHT_FD_FILESTAT_SET_TIMES = 8388608N
|
|
237
|
+
@unsafe
|
|
211
238
|
let _RIGHT_PATH_SYMLINK = 16777216N
|
|
239
|
+
@unsafe
|
|
212
240
|
let _RIGHT_PATH_REMOVE_DIRECTORY = 33554432N
|
|
241
|
+
@unsafe
|
|
213
242
|
let _RIGHT_PATH_UNLINK_FILE = 67108864N
|
|
243
|
+
@unsafe
|
|
214
244
|
let _RIGHT_POLL_FD_READWRITE = 134217728N
|
|
245
|
+
@unsafe
|
|
215
246
|
let _RIGHT_SOCK_SHUTDOWN = 268435456N
|
|
216
247
|
|
|
217
248
|
// TODO(#775): This has specific ordering requirements because of ambiguous type inference
|
|
249
|
+
@unsafe
|
|
218
250
|
let rec combineRightsHelp = (acc, dirflags) => {
|
|
219
251
|
match (dirflags) {
|
|
220
252
|
[] => acc,
|
|
@@ -249,12 +281,18 @@ let rec combineRightsHelp = (acc, dirflags) => {
|
|
|
249
281
|
PathUnlinkFile => _RIGHT_PATH_UNLINK_FILE,
|
|
250
282
|
PollFdReadwrite => _RIGHT_POLL_FD_READWRITE,
|
|
251
283
|
SockShutdown => _RIGHT_SOCK_SHUTDOWN,
|
|
252
|
-
_ =>
|
|
284
|
+
_ => {
|
|
285
|
+
ignore(fail "Unknown file right")
|
|
286
|
+
// `fail` won't allow us to get here, but this is necessary
|
|
287
|
+
// to make the wasm types work out
|
|
288
|
+
0N
|
|
289
|
+
},
|
|
253
290
|
}
|
|
254
291
|
combineRightsHelp(WasmI64.or(flag, acc), tl)
|
|
255
292
|
},
|
|
256
293
|
}
|
|
257
294
|
}
|
|
295
|
+
@unsafe
|
|
258
296
|
let combineRights = dirflags => {
|
|
259
297
|
combineRightsHelp(0N, dirflags)
|
|
260
298
|
}
|
|
@@ -278,6 +316,7 @@ export enum FdFlag {
|
|
|
278
316
|
}
|
|
279
317
|
|
|
280
318
|
// TODO(#775): This has specific ordering requirements because of ambiguous type inference
|
|
319
|
+
@unsafe
|
|
281
320
|
let rec combineFdFlagsHelp = (acc, dirflags) => {
|
|
282
321
|
match (dirflags) {
|
|
283
322
|
[hd, ...tl] => {
|
|
@@ -293,6 +332,7 @@ let rec combineFdFlagsHelp = (acc, dirflags) => {
|
|
|
293
332
|
[] => acc,
|
|
294
333
|
}
|
|
295
334
|
}
|
|
335
|
+
@unsafe
|
|
296
336
|
let combineFdFlags = dirflags => {
|
|
297
337
|
combineFdFlagsHelp(0n, dirflags)
|
|
298
338
|
}
|
|
@@ -320,6 +360,7 @@ export enum Filetype {
|
|
|
320
360
|
}
|
|
321
361
|
|
|
322
362
|
// TODO(#775): This has specific ordering requirements because of ambiguous type inference
|
|
363
|
+
@unsafe
|
|
323
364
|
let filetypeFromNumber = filetype => {
|
|
324
365
|
match (filetype) {
|
|
325
366
|
0n => Unknown,
|
|
@@ -400,18 +441,6 @@ export let stderr = FileDescriptor(2)
|
|
|
400
441
|
*/
|
|
401
442
|
export let pwdfd = FileDescriptor(3)
|
|
402
443
|
|
|
403
|
-
let wasmSafeOk = val => {
|
|
404
|
-
Memory.incRef(WasmI32.fromGrain(Ok))
|
|
405
|
-
Memory.incRef(WasmI32.fromGrain(val))
|
|
406
|
-
Ok(val)
|
|
407
|
-
}
|
|
408
|
-
|
|
409
|
-
let wasmSafeErr = err => {
|
|
410
|
-
Memory.incRef(WasmI32.fromGrain(Err))
|
|
411
|
-
Memory.incRef(WasmI32.fromGrain(err))
|
|
412
|
-
Err(err)
|
|
413
|
-
}
|
|
414
|
-
|
|
415
444
|
/**
|
|
416
445
|
* Open a file or directory.
|
|
417
446
|
*
|
|
@@ -424,7 +453,8 @@ let wasmSafeErr = err => {
|
|
|
424
453
|
* @param flags: Flags which affect read/write operations on this file descriptor
|
|
425
454
|
* @returns `Ok(fd)` of the opened file or directory if successful or `Err(exception)` otherwise
|
|
426
455
|
*/
|
|
427
|
-
|
|
456
|
+
@unsafe
|
|
457
|
+
export let pathOpen =
|
|
428
458
|
(
|
|
429
459
|
dirFd: FileDescriptor,
|
|
430
460
|
dirFlags: List<LookupFlag>,
|
|
@@ -465,25 +495,16 @@ export let rec pathOpen =
|
|
|
465
495
|
combinedFsFlags,
|
|
466
496
|
newFd
|
|
467
497
|
)
|
|
468
|
-
|
|
498
|
+
if (err != Wasi._ESUCCESS) {
|
|
469
499
|
Memory.free(newFd)
|
|
470
|
-
|
|
500
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
471
501
|
} else {
|
|
472
502
|
let fd = FileDescriptor(tagSimpleNumber(WasmI32.load(newFd, 0n)))
|
|
473
503
|
|
|
474
504
|
Memory.free(newFd)
|
|
475
505
|
|
|
476
|
-
|
|
506
|
+
Ok(fd)
|
|
477
507
|
}
|
|
478
|
-
Memory.decRef(WasmI32.fromGrain(dirFdArg))
|
|
479
|
-
Memory.decRef(WasmI32.fromGrain(dirFlags))
|
|
480
|
-
Memory.decRef(WasmI32.fromGrain(pathArg))
|
|
481
|
-
Memory.decRef(WasmI32.fromGrain(openFlags))
|
|
482
|
-
Memory.decRef(WasmI32.fromGrain(rights))
|
|
483
|
-
Memory.decRef(WasmI32.fromGrain(rightsInheritingArg))
|
|
484
|
-
Memory.decRef(WasmI32.fromGrain(flags))
|
|
485
|
-
Memory.decRef(WasmI32.fromGrain(pathOpen))
|
|
486
|
-
ret
|
|
487
508
|
}
|
|
488
509
|
|
|
489
510
|
/**
|
|
@@ -493,7 +514,8 @@ export let rec pathOpen =
|
|
|
493
514
|
* @param size: The maximum number of bytes to read from the file descriptor
|
|
494
515
|
* @returns `Ok((contents, numBytes))` of bytes read and the number of bytes read if successful or `Err(exception)` otherwise
|
|
495
516
|
*/
|
|
496
|
-
|
|
517
|
+
@unsafe
|
|
518
|
+
export let fdRead = (fd: FileDescriptor, size: Number) => {
|
|
497
519
|
let fdArg = fd
|
|
498
520
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
499
521
|
|
|
@@ -508,10 +530,10 @@ export let rec fdRead = (fd: FileDescriptor, size: Number) => {
|
|
|
508
530
|
let mut nread = iovs + 3n * 4n
|
|
509
531
|
|
|
510
532
|
let err = Wasi.fd_read(fd, iovs, 1n, nread)
|
|
511
|
-
|
|
533
|
+
if (err != Wasi._ESUCCESS) {
|
|
512
534
|
Memory.free(iovs)
|
|
513
535
|
Memory.free(strPtr)
|
|
514
|
-
|
|
536
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
515
537
|
} else {
|
|
516
538
|
nread = WasmI32.load(nread, 0n)
|
|
517
539
|
|
|
@@ -519,12 +541,8 @@ export let rec fdRead = (fd: FileDescriptor, size: Number) => {
|
|
|
519
541
|
|
|
520
542
|
Memory.free(iovs)
|
|
521
543
|
|
|
522
|
-
|
|
544
|
+
Ok((WasmI32.toGrain(strPtr): String, tagSimpleNumber(nread)))
|
|
523
545
|
}
|
|
524
|
-
Memory.decRef(WasmI32.fromGrain(fd))
|
|
525
|
-
Memory.decRef(WasmI32.fromGrain(size))
|
|
526
|
-
Memory.decRef(WasmI32.fromGrain(fdRead))
|
|
527
|
-
ret
|
|
528
546
|
}
|
|
529
547
|
|
|
530
548
|
/**
|
|
@@ -535,7 +553,8 @@ export let rec fdRead = (fd: FileDescriptor, size: Number) => {
|
|
|
535
553
|
* @param size: The maximum number of bytes to read from the file descriptor
|
|
536
554
|
* @returns `Ok((contents, numBytes))` of bytes read and the number of bytes read if successful or `Err(exception)` otherwise
|
|
537
555
|
*/
|
|
538
|
-
|
|
556
|
+
@unsafe
|
|
557
|
+
export let fdPread = (fd: FileDescriptor, offset: Int64, size: Number) => {
|
|
539
558
|
let fdArg = fd
|
|
540
559
|
let offsetArg = offset
|
|
541
560
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
@@ -553,10 +572,10 @@ export let rec fdPread = (fd: FileDescriptor, offset: Int64, size: Number) => {
|
|
|
553
572
|
let mut nread = iovs + 3n * 4n
|
|
554
573
|
|
|
555
574
|
let err = Wasi.fd_pread(fd, iovs, 1n, offset, nread)
|
|
556
|
-
|
|
575
|
+
if (err != Wasi._ESUCCESS) {
|
|
557
576
|
Memory.free(iovs)
|
|
558
577
|
Memory.free(strPtr)
|
|
559
|
-
|
|
578
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
560
579
|
} else {
|
|
561
580
|
nread = WasmI32.load(nread, 0n)
|
|
562
581
|
|
|
@@ -564,13 +583,8 @@ export let rec fdPread = (fd: FileDescriptor, offset: Int64, size: Number) => {
|
|
|
564
583
|
|
|
565
584
|
Memory.free(iovs)
|
|
566
585
|
|
|
567
|
-
|
|
586
|
+
Ok((WasmI32.toGrain(strPtr): String, tagSimpleNumber(nread)))
|
|
568
587
|
}
|
|
569
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
570
|
-
Memory.decRef(WasmI32.fromGrain(offsetArg))
|
|
571
|
-
Memory.decRef(WasmI32.fromGrain(size))
|
|
572
|
-
Memory.decRef(WasmI32.fromGrain(fdPread))
|
|
573
|
-
ret
|
|
574
588
|
}
|
|
575
589
|
|
|
576
590
|
/**
|
|
@@ -580,7 +594,8 @@ export let rec fdPread = (fd: FileDescriptor, offset: Int64, size: Number) => {
|
|
|
580
594
|
* @param data: The data to be written
|
|
581
595
|
* @returns `Ok(numBytes)` of the number of bytes written if successful or `Err(Exception)` otherwise
|
|
582
596
|
*/
|
|
583
|
-
|
|
597
|
+
@unsafe
|
|
598
|
+
export let fdWrite = (fd: FileDescriptor, data: String) => {
|
|
584
599
|
let fdArg = fd
|
|
585
600
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
586
601
|
|
|
@@ -593,20 +608,16 @@ export let rec fdWrite = (fd: FileDescriptor, data: String) => {
|
|
|
593
608
|
let mut nwritten = iovs + 3n * 4n
|
|
594
609
|
|
|
595
610
|
let err = Wasi.fd_write(fd, iovs, 1n, nwritten)
|
|
596
|
-
|
|
611
|
+
if (err != Wasi._ESUCCESS) {
|
|
597
612
|
Memory.free(iovs)
|
|
598
|
-
|
|
613
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
599
614
|
} else {
|
|
600
615
|
nwritten = WasmI32.load(nwritten, 0n)
|
|
601
616
|
|
|
602
617
|
Memory.free(iovs)
|
|
603
618
|
|
|
604
|
-
|
|
619
|
+
Ok(tagSimpleNumber(nwritten))
|
|
605
620
|
}
|
|
606
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
607
|
-
Memory.decRef(WasmI32.fromGrain(data))
|
|
608
|
-
Memory.decRef(WasmI32.fromGrain(fdWrite))
|
|
609
|
-
ret
|
|
610
621
|
}
|
|
611
622
|
|
|
612
623
|
/**
|
|
@@ -617,7 +628,8 @@ export let rec fdWrite = (fd: FileDescriptor, data: String) => {
|
|
|
617
628
|
* @param offset: The position within the file to begin writing
|
|
618
629
|
* @returns `Ok(numBytes)` of the number of bytes written if successful or `Err(exception)` otherwise
|
|
619
630
|
*/
|
|
620
|
-
|
|
631
|
+
@unsafe
|
|
632
|
+
export let fdPwrite = (fd: FileDescriptor, data: String, offset: Int64) => {
|
|
621
633
|
let fdArg = fd
|
|
622
634
|
let offsetArg = offset
|
|
623
635
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
@@ -633,21 +645,16 @@ export let rec fdPwrite = (fd: FileDescriptor, data: String, offset: Int64) => {
|
|
|
633
645
|
let mut nwritten = iovs + 3n * 4n
|
|
634
646
|
|
|
635
647
|
let err = Wasi.fd_pwrite(fd, iovs, 1n, offset, nwritten)
|
|
636
|
-
|
|
648
|
+
if (err != Wasi._ESUCCESS) {
|
|
637
649
|
Memory.free(iovs)
|
|
638
|
-
|
|
650
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
639
651
|
} else {
|
|
640
652
|
nwritten = WasmI32.load(nwritten, 0n)
|
|
641
653
|
|
|
642
654
|
Memory.free(iovs)
|
|
643
655
|
|
|
644
|
-
|
|
656
|
+
Ok(tagSimpleNumber(nwritten))
|
|
645
657
|
}
|
|
646
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
647
|
-
Memory.decRef(WasmI32.fromGrain(data))
|
|
648
|
-
Memory.decRef(WasmI32.fromGrain(offsetArg))
|
|
649
|
-
Memory.decRef(WasmI32.fromGrain(fdPwrite))
|
|
650
|
-
ret
|
|
651
658
|
}
|
|
652
659
|
|
|
653
660
|
/**
|
|
@@ -658,12 +665,8 @@ export let rec fdPwrite = (fd: FileDescriptor, data: String, offset: Int64) => {
|
|
|
658
665
|
* @param size: The number of bytes to allocate
|
|
659
666
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
660
667
|
*/
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
fd: FileDescriptor,
|
|
664
|
-
offset: Int64,
|
|
665
|
-
size: Int64,
|
|
666
|
-
) => {
|
|
668
|
+
@unsafe
|
|
669
|
+
export let fdAllocate = (fd: FileDescriptor, offset: Int64, size: Int64) => {
|
|
667
670
|
let fdArg = fd
|
|
668
671
|
let offsetArg = offset
|
|
669
672
|
let sizeArg = size
|
|
@@ -674,16 +677,11 @@ export let rec fdAllocate =
|
|
|
674
677
|
let size = WasmI64.load(WasmI32.fromGrain(size), 8n)
|
|
675
678
|
|
|
676
679
|
let err = Wasi.fd_allocate(fd, offset, size)
|
|
677
|
-
|
|
678
|
-
|
|
680
|
+
if (err != Wasi._ESUCCESS) {
|
|
681
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
679
682
|
} else {
|
|
680
|
-
|
|
683
|
+
Ok(void)
|
|
681
684
|
}
|
|
682
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
683
|
-
Memory.decRef(WasmI32.fromGrain(offsetArg))
|
|
684
|
-
Memory.decRef(WasmI32.fromGrain(sizeArg))
|
|
685
|
-
Memory.decRef(WasmI32.fromGrain(fdAllocate))
|
|
686
|
-
ret
|
|
687
685
|
}
|
|
688
686
|
|
|
689
687
|
/**
|
|
@@ -692,19 +690,17 @@ export let rec fdAllocate =
|
|
|
692
690
|
* @param fd: The file descriptor to close
|
|
693
691
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
694
692
|
*/
|
|
695
|
-
|
|
693
|
+
@unsafe
|
|
694
|
+
export let fdClose = (fd: FileDescriptor) => {
|
|
696
695
|
let fdArg = fd
|
|
697
696
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
698
697
|
|
|
699
698
|
let err = Wasi.fd_close(fd)
|
|
700
|
-
|
|
701
|
-
|
|
699
|
+
if (err != Wasi._ESUCCESS) {
|
|
700
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
702
701
|
} else {
|
|
703
|
-
|
|
702
|
+
Ok(void)
|
|
704
703
|
}
|
|
705
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
706
|
-
Memory.decRef(WasmI32.fromGrain(fdClose))
|
|
707
|
-
ret
|
|
708
704
|
}
|
|
709
705
|
|
|
710
706
|
/**
|
|
@@ -713,19 +709,17 @@ export let rec fdClose = (fd: FileDescriptor) => {
|
|
|
713
709
|
* @param fd: The file descriptor to synchronize
|
|
714
710
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
715
711
|
*/
|
|
716
|
-
|
|
712
|
+
@unsafe
|
|
713
|
+
export let fdDatasync = (fd: FileDescriptor) => {
|
|
717
714
|
let fdArg = fd
|
|
718
715
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
719
716
|
|
|
720
717
|
let err = Wasi.fd_datasync(fd)
|
|
721
|
-
|
|
722
|
-
|
|
718
|
+
if (err != Wasi._ESUCCESS) {
|
|
719
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
723
720
|
} else {
|
|
724
|
-
|
|
721
|
+
Ok(void)
|
|
725
722
|
}
|
|
726
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
727
|
-
Memory.decRef(WasmI32.fromGrain(fdDatasync))
|
|
728
|
-
ret
|
|
729
723
|
}
|
|
730
724
|
|
|
731
725
|
/**
|
|
@@ -734,127 +728,51 @@ export let rec fdDatasync = (fd: FileDescriptor) => {
|
|
|
734
728
|
* @param fd: The file descriptor to synchronize
|
|
735
729
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
736
730
|
*/
|
|
737
|
-
|
|
731
|
+
@unsafe
|
|
732
|
+
export let fdSync = (fd: FileDescriptor) => {
|
|
738
733
|
let fdArg = fd
|
|
739
734
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
740
735
|
|
|
741
736
|
let err = Wasi.fd_sync(fd)
|
|
742
|
-
|
|
743
|
-
|
|
737
|
+
if (err != Wasi._ESUCCESS) {
|
|
738
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
744
739
|
} else {
|
|
745
|
-
|
|
740
|
+
Ok(void)
|
|
746
741
|
}
|
|
747
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
748
|
-
Memory.decRef(WasmI32.fromGrain(fdSync))
|
|
749
|
-
ret
|
|
750
|
-
}
|
|
751
|
-
|
|
752
|
-
let wasmSafeCons = (a, b) => {
|
|
753
|
-
// [TODO] Once grain-lang/grain#802 is fixed:
|
|
754
|
-
// Memory.incRef(WasmI32.fromGrain([...]))
|
|
755
|
-
Memory.incRef(WasmI32.fromGrain(cons))
|
|
756
|
-
Memory.incRef(WasmI32.fromGrain(a))
|
|
757
|
-
Memory.incRef(WasmI32.fromGrain(b))
|
|
758
|
-
cons(a, b)
|
|
759
|
-
// [TODO] Once grain-lang/grain#802 is fixed:
|
|
760
|
-
// [a, ...b]
|
|
761
742
|
}
|
|
762
743
|
|
|
763
|
-
let orderedFdflags =
|
|
764
|
-
|
|
765
|
-
wasmSafeCons(
|
|
766
|
-
Dsync,
|
|
767
|
-
wasmSafeCons(Nonblock, wasmSafeCons(Rsync, wasmSafeCons(Sync, [])))
|
|
768
|
-
)
|
|
769
|
-
)
|
|
770
|
-
let orderedRights = wasmSafeCons(
|
|
744
|
+
let orderedFdflags = [Append, Dsync, Nonblock, Rsync, Sync]
|
|
745
|
+
let orderedRights = [
|
|
771
746
|
FdDatasync,
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
PathReadlink,
|
|
802
|
-
wasmSafeCons(
|
|
803
|
-
PathRenameSource,
|
|
804
|
-
wasmSafeCons(
|
|
805
|
-
PathRenameTarget,
|
|
806
|
-
wasmSafeCons(
|
|
807
|
-
PathFilestats,
|
|
808
|
-
wasmSafeCons(
|
|
809
|
-
PathSetSize,
|
|
810
|
-
wasmSafeCons(
|
|
811
|
-
PathSetTimes,
|
|
812
|
-
wasmSafeCons(
|
|
813
|
-
FdFilestats,
|
|
814
|
-
wasmSafeCons(
|
|
815
|
-
FdSetSize,
|
|
816
|
-
wasmSafeCons(
|
|
817
|
-
FdSetTimes,
|
|
818
|
-
wasmSafeCons(
|
|
819
|
-
PathSymlink,
|
|
820
|
-
wasmSafeCons(
|
|
821
|
-
PathRemoveDirectory,
|
|
822
|
-
wasmSafeCons(
|
|
823
|
-
PathUnlinkFile,
|
|
824
|
-
wasmSafeCons(
|
|
825
|
-
PollFdReadwrite,
|
|
826
|
-
wasmSafeCons(
|
|
827
|
-
SockShutdown,
|
|
828
|
-
[]
|
|
829
|
-
)
|
|
830
|
-
)
|
|
831
|
-
)
|
|
832
|
-
)
|
|
833
|
-
)
|
|
834
|
-
)
|
|
835
|
-
)
|
|
836
|
-
)
|
|
837
|
-
)
|
|
838
|
-
)
|
|
839
|
-
)
|
|
840
|
-
)
|
|
841
|
-
)
|
|
842
|
-
)
|
|
843
|
-
)
|
|
844
|
-
)
|
|
845
|
-
)
|
|
846
|
-
)
|
|
847
|
-
)
|
|
848
|
-
)
|
|
849
|
-
)
|
|
850
|
-
)
|
|
851
|
-
)
|
|
852
|
-
)
|
|
853
|
-
)
|
|
854
|
-
)
|
|
855
|
-
)
|
|
856
|
-
)
|
|
857
|
-
)
|
|
747
|
+
FdRead,
|
|
748
|
+
FdSeek,
|
|
749
|
+
FdSetFlags,
|
|
750
|
+
FdSync,
|
|
751
|
+
FdTell,
|
|
752
|
+
FdWrite,
|
|
753
|
+
FdAdvise,
|
|
754
|
+
FdAllocate,
|
|
755
|
+
PathCreateDirectory,
|
|
756
|
+
PathCreateFile,
|
|
757
|
+
PathLinkSource,
|
|
758
|
+
PathLinkTarget,
|
|
759
|
+
PathOpen,
|
|
760
|
+
FdReaddir,
|
|
761
|
+
PathReadlink,
|
|
762
|
+
PathRenameSource,
|
|
763
|
+
PathRenameTarget,
|
|
764
|
+
PathFilestats,
|
|
765
|
+
PathSetSize,
|
|
766
|
+
PathSetTimes,
|
|
767
|
+
FdFilestats,
|
|
768
|
+
FdSetSize,
|
|
769
|
+
FdSetTimes,
|
|
770
|
+
PathSymlink,
|
|
771
|
+
PathRemoveDirectory,
|
|
772
|
+
PathUnlinkFile,
|
|
773
|
+
PollFdReadwrite,
|
|
774
|
+
SockShutdown,
|
|
775
|
+
]
|
|
858
776
|
|
|
859
777
|
/**
|
|
860
778
|
* Retrieve information about a file descriptor.
|
|
@@ -862,16 +780,17 @@ let orderedRights = wasmSafeCons(
|
|
|
862
780
|
* @param fd: The file descriptor of which to retrieve information
|
|
863
781
|
* @returns `Ok(stats)` of the `Stats` associated with the file descriptor if successful or `Err(exception)` otherwise
|
|
864
782
|
*/
|
|
865
|
-
|
|
783
|
+
@unsafe
|
|
784
|
+
export let fdStats = (fd: FileDescriptor) => {
|
|
866
785
|
let fdArg = fd
|
|
867
786
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
868
787
|
|
|
869
788
|
let structPtr = Memory.malloc(24n)
|
|
870
789
|
|
|
871
790
|
let err = Wasi.fd_fdstat_get(fd, structPtr)
|
|
872
|
-
|
|
791
|
+
if (err != Wasi._ESUCCESS) {
|
|
873
792
|
Memory.free(structPtr)
|
|
874
|
-
|
|
793
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
875
794
|
} else {
|
|
876
795
|
let filetype = WasmI32.load8U(structPtr, 0n)
|
|
877
796
|
|
|
@@ -881,11 +800,7 @@ export let rec fdStats = (fd: FileDescriptor) => {
|
|
|
881
800
|
let fdflags = WasmI32.load16U(structPtr, 4n)
|
|
882
801
|
WasmI32.gtU(fdflags & 1n << (WasmI32.fromGrain(i) >> 1n), 0n)
|
|
883
802
|
}
|
|
884
|
-
Memory.incRef(WasmI32.fromGrain(List.filteri))
|
|
885
|
-
Memory.incRef(WasmI32.fromGrain(flagsToWasmVal))
|
|
886
|
-
Memory.incRef(WasmI32.fromGrain(orderedFdflags))
|
|
887
803
|
let fdflagsList = List.filteri(flagsToWasmVal, orderedFdflags)
|
|
888
|
-
Memory.free(WasmI32.fromGrain(flagsToWasmVal))
|
|
889
804
|
|
|
890
805
|
let (&) = WasmI64.and
|
|
891
806
|
let (>) = WasmI64.gtU
|
|
@@ -895,11 +810,7 @@ export let rec fdStats = (fd: FileDescriptor) => {
|
|
|
895
810
|
let rights = WasmI64.load(structPtr, 8n)
|
|
896
811
|
(rights & 1N << WasmI64.extendI32U(WasmI32.fromGrain(i) >> 1n)) > 0N
|
|
897
812
|
}
|
|
898
|
-
Memory.incRef(WasmI32.fromGrain(List.filteri))
|
|
899
|
-
Memory.incRef(WasmI32.fromGrain(flagsToWasmVal))
|
|
900
|
-
Memory.incRef(WasmI32.fromGrain(orderedRights))
|
|
901
813
|
let rightsList = List.filteri(flagsToWasmVal, orderedRights)
|
|
902
|
-
Memory.free(WasmI32.fromGrain(flagsToWasmVal))
|
|
903
814
|
|
|
904
815
|
let flagsToWasmVal = (flag, i) => {
|
|
905
816
|
let rightsInheriting = WasmI64.load(structPtr, 16n)
|
|
@@ -907,15 +818,11 @@ export let rec fdStats = (fd: FileDescriptor) => {
|
|
|
907
818
|
1N << WasmI64.extendI32U(WasmI32.fromGrain(i) >> 1n)) >
|
|
908
819
|
0N
|
|
909
820
|
}
|
|
910
|
-
Memory.incRef(WasmI32.fromGrain(List.filteri))
|
|
911
|
-
Memory.incRef(WasmI32.fromGrain(flagsToWasmVal))
|
|
912
|
-
Memory.incRef(WasmI32.fromGrain(orderedRights))
|
|
913
821
|
let rightsInheritingList = List.filteri(flagsToWasmVal, orderedRights)
|
|
914
|
-
Memory.free(WasmI32.fromGrain(flagsToWasmVal))
|
|
915
822
|
|
|
916
823
|
Memory.free(structPtr)
|
|
917
824
|
|
|
918
|
-
|
|
825
|
+
Ok(
|
|
919
826
|
{
|
|
920
827
|
filetype,
|
|
921
828
|
flags: fdflagsList,
|
|
@@ -924,9 +831,6 @@ export let rec fdStats = (fd: FileDescriptor) => {
|
|
|
924
831
|
}
|
|
925
832
|
)
|
|
926
833
|
}
|
|
927
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
928
|
-
Memory.decRef(WasmI32.fromGrain(fdStats))
|
|
929
|
-
ret
|
|
930
834
|
}
|
|
931
835
|
|
|
932
836
|
/**
|
|
@@ -936,7 +840,8 @@ export let rec fdStats = (fd: FileDescriptor) => {
|
|
|
936
840
|
* @param flags: The flags to apply to the file descriptor
|
|
937
841
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
938
842
|
*/
|
|
939
|
-
|
|
843
|
+
@unsafe
|
|
844
|
+
export let fdSetFlags = (fd: FileDescriptor, flags: List<FdFlag>) => {
|
|
940
845
|
let fdArg = fd
|
|
941
846
|
let flagsArg = flags
|
|
942
847
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
@@ -944,15 +849,11 @@ export let rec fdSetFlags = (fd: FileDescriptor, flags: List<FdFlag>) => {
|
|
|
944
849
|
let flags = combineFdFlags(flags)
|
|
945
850
|
|
|
946
851
|
let err = Wasi.fd_fdstat_set_flags(fd, flags)
|
|
947
|
-
|
|
948
|
-
|
|
852
|
+
if (err != Wasi._ESUCCESS) {
|
|
853
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
949
854
|
} else {
|
|
950
|
-
|
|
855
|
+
Ok(void)
|
|
951
856
|
}
|
|
952
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
953
|
-
Memory.decRef(WasmI32.fromGrain(flagsArg))
|
|
954
|
-
Memory.decRef(WasmI32.fromGrain(fdSetFlags))
|
|
955
|
-
ret
|
|
956
857
|
}
|
|
957
858
|
|
|
958
859
|
/**
|
|
@@ -963,7 +864,8 @@ export let rec fdSetFlags = (fd: FileDescriptor, flags: List<FdFlag>) => {
|
|
|
963
864
|
* @param rightsInheriting: Inheriting rights to apply to the file descriptor
|
|
964
865
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
965
866
|
*/
|
|
966
|
-
|
|
867
|
+
@unsafe
|
|
868
|
+
export let fdSetRights =
|
|
967
869
|
(
|
|
968
870
|
fd: FileDescriptor,
|
|
969
871
|
rights: List<Rights>,
|
|
@@ -978,16 +880,11 @@ export let rec fdSetRights =
|
|
|
978
880
|
let rightsInheriting = combineRights(rightsInheriting)
|
|
979
881
|
|
|
980
882
|
let err = Wasi.fd_fdstat_set_rights(fd, rights, rightsInheriting)
|
|
981
|
-
|
|
982
|
-
|
|
883
|
+
if (err != Wasi._ESUCCESS) {
|
|
884
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
983
885
|
} else {
|
|
984
|
-
|
|
886
|
+
Ok(void)
|
|
985
887
|
}
|
|
986
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
987
|
-
Memory.decRef(WasmI32.fromGrain(rightsArg))
|
|
988
|
-
Memory.decRef(WasmI32.fromGrain(rightsInheritingArg))
|
|
989
|
-
Memory.decRef(WasmI32.fromGrain(fdSetRights))
|
|
990
|
-
ret
|
|
991
888
|
}
|
|
992
889
|
|
|
993
890
|
/**
|
|
@@ -996,16 +893,17 @@ export let rec fdSetRights =
|
|
|
996
893
|
* @param fd: The file descriptor of the file to retrieve information
|
|
997
894
|
* @returns `Ok(info)` of the `Filestats` associated with the file descriptor if successful or `Err(exception)` otherwise
|
|
998
895
|
*/
|
|
999
|
-
|
|
896
|
+
@unsafe
|
|
897
|
+
export let fdFilestats = (fd: FileDescriptor) => {
|
|
1000
898
|
let fdArg = fd
|
|
1001
899
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1002
900
|
|
|
1003
901
|
let filestats = Memory.malloc(64n)
|
|
1004
902
|
|
|
1005
903
|
let err = Wasi.fd_filestat_get(fd, filestats)
|
|
1006
|
-
|
|
904
|
+
if (err != Wasi._ESUCCESS) {
|
|
1007
905
|
Memory.free(filestats)
|
|
1008
|
-
|
|
906
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1009
907
|
} else {
|
|
1010
908
|
let device = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 0n))): Int64
|
|
1011
909
|
let inode = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 8n))): Int64
|
|
@@ -1024,13 +922,10 @@ export let rec fdFilestats = (fd: FileDescriptor) => {
|
|
|
1024
922
|
|
|
1025
923
|
Memory.free(filestats)
|
|
1026
924
|
|
|
1027
|
-
|
|
925
|
+
Ok(
|
|
1028
926
|
{ device, inode, filetype, linkcount, size, accessed, modified, changed }
|
|
1029
927
|
)
|
|
1030
928
|
}
|
|
1031
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1032
|
-
Memory.decRef(WasmI32.fromGrain(fdFilestats))
|
|
1033
|
-
ret
|
|
1034
929
|
}
|
|
1035
930
|
|
|
1036
931
|
/**
|
|
@@ -1040,7 +935,8 @@ export let rec fdFilestats = (fd: FileDescriptor) => {
|
|
|
1040
935
|
* @param size: The number of bytes to retain in the file
|
|
1041
936
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1042
937
|
*/
|
|
1043
|
-
|
|
938
|
+
@unsafe
|
|
939
|
+
export let fdSetSize = (fd: FileDescriptor, size: Int64) => {
|
|
1044
940
|
let fdArg = fd
|
|
1045
941
|
let sizeArg = size
|
|
1046
942
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
@@ -1048,15 +944,11 @@ export let rec fdSetSize = (fd: FileDescriptor, size: Int64) => {
|
|
|
1048
944
|
let size = WasmI64.load(WasmI32.fromGrain(size), 8n)
|
|
1049
945
|
|
|
1050
946
|
let err = Wasi.fd_filestat_set_size(fd, size)
|
|
1051
|
-
|
|
1052
|
-
|
|
947
|
+
if (err != Wasi._ESUCCESS) {
|
|
948
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1053
949
|
} else {
|
|
1054
|
-
|
|
950
|
+
Ok(void)
|
|
1055
951
|
}
|
|
1056
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1057
|
-
Memory.decRef(WasmI32.fromGrain(sizeArg))
|
|
1058
|
-
Memory.decRef(WasmI32.fromGrain(fdSetSize))
|
|
1059
|
-
ret
|
|
1060
952
|
}
|
|
1061
953
|
|
|
1062
954
|
/**
|
|
@@ -1066,22 +958,19 @@ export let rec fdSetSize = (fd: FileDescriptor, size: Int64) => {
|
|
|
1066
958
|
* @param timestamp: The time to set
|
|
1067
959
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1068
960
|
*/
|
|
1069
|
-
|
|
961
|
+
@unsafe
|
|
962
|
+
export let fdSetAccessTime = (fd: FileDescriptor, timestamp: Int64) => {
|
|
1070
963
|
let fdArg = fd
|
|
1071
964
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1072
965
|
|
|
1073
966
|
let time = WasmI64.load(WasmI32.fromGrain(timestamp), 8n)
|
|
1074
967
|
|
|
1075
968
|
let err = Wasi.fd_filestat_set_times(fd, time, 0N, Wasi._TIME_SET_ATIM)
|
|
1076
|
-
|
|
1077
|
-
|
|
969
|
+
if (err != Wasi._ESUCCESS) {
|
|
970
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1078
971
|
} else {
|
|
1079
|
-
|
|
972
|
+
Ok(void)
|
|
1080
973
|
}
|
|
1081
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1082
|
-
Memory.decRef(WasmI32.fromGrain(timestamp))
|
|
1083
|
-
Memory.decRef(WasmI32.fromGrain(fdSetAccessTime))
|
|
1084
|
-
ret
|
|
1085
974
|
}
|
|
1086
975
|
|
|
1087
976
|
/**
|
|
@@ -1090,19 +979,17 @@ export let rec fdSetAccessTime = (fd: FileDescriptor, timestamp: Int64) => {
|
|
|
1090
979
|
* @param fd: The file descriptor of the file to update
|
|
1091
980
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1092
981
|
*/
|
|
1093
|
-
|
|
982
|
+
@unsafe
|
|
983
|
+
export let fdSetAccessTimeNow = (fd: FileDescriptor) => {
|
|
1094
984
|
let fdArg = fd
|
|
1095
985
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1096
986
|
|
|
1097
987
|
let err = Wasi.fd_filestat_set_times(fd, 0N, 0N, Wasi._TIME_SET_ATIM_NOW)
|
|
1098
|
-
|
|
1099
|
-
|
|
988
|
+
if (err != Wasi._ESUCCESS) {
|
|
989
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1100
990
|
} else {
|
|
1101
|
-
|
|
991
|
+
Ok(void)
|
|
1102
992
|
}
|
|
1103
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1104
|
-
Memory.decRef(WasmI32.fromGrain(fdSetAccessTimeNow))
|
|
1105
|
-
ret
|
|
1106
993
|
}
|
|
1107
994
|
|
|
1108
995
|
/**
|
|
@@ -1112,22 +999,19 @@ export let rec fdSetAccessTimeNow = (fd: FileDescriptor) => {
|
|
|
1112
999
|
* @param timestamp: The time to set
|
|
1113
1000
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1114
1001
|
*/
|
|
1115
|
-
|
|
1002
|
+
@unsafe
|
|
1003
|
+
export let fdSetModifiedTime = (fd: FileDescriptor, timestamp: Int64) => {
|
|
1116
1004
|
let fdArg = fd
|
|
1117
1005
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1118
1006
|
|
|
1119
1007
|
let time = WasmI64.load(WasmI32.fromGrain(timestamp), 8n)
|
|
1120
1008
|
|
|
1121
1009
|
let err = Wasi.fd_filestat_set_times(fd, 0N, time, Wasi._TIME_SET_MTIM)
|
|
1122
|
-
|
|
1123
|
-
|
|
1010
|
+
if (err != Wasi._ESUCCESS) {
|
|
1011
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1124
1012
|
} else {
|
|
1125
|
-
|
|
1013
|
+
Ok(void)
|
|
1126
1014
|
}
|
|
1127
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1128
|
-
Memory.decRef(WasmI32.fromGrain(timestamp))
|
|
1129
|
-
Memory.decRef(WasmI32.fromGrain(fdSetModifiedTime))
|
|
1130
|
-
ret
|
|
1131
1015
|
}
|
|
1132
1016
|
|
|
1133
1017
|
/**
|
|
@@ -1136,19 +1020,17 @@ export let rec fdSetModifiedTime = (fd: FileDescriptor, timestamp: Int64) => {
|
|
|
1136
1020
|
* @param fd: The file descriptor of the file to update
|
|
1137
1021
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1138
1022
|
*/
|
|
1139
|
-
|
|
1023
|
+
@unsafe
|
|
1024
|
+
export let fdSetModifiedTimeNow = (fd: FileDescriptor) => {
|
|
1140
1025
|
let fdArg = fd
|
|
1141
1026
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1142
1027
|
|
|
1143
1028
|
let err = Wasi.fd_filestat_set_times(fd, 0N, 0N, Wasi._TIME_SET_MTIM_NOW)
|
|
1144
|
-
|
|
1145
|
-
|
|
1029
|
+
if (err != Wasi._ESUCCESS) {
|
|
1030
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1146
1031
|
} else {
|
|
1147
|
-
|
|
1032
|
+
Ok(void)
|
|
1148
1033
|
}
|
|
1149
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1150
|
-
Memory.decRef(WasmI32.fromGrain(fdSetModifiedTime))
|
|
1151
|
-
ret
|
|
1152
1034
|
}
|
|
1153
1035
|
|
|
1154
1036
|
/**
|
|
@@ -1157,7 +1039,8 @@ export let rec fdSetModifiedTimeNow = (fd: FileDescriptor) => {
|
|
|
1157
1039
|
* @param fd: The directory to read
|
|
1158
1040
|
* @returns `Ok(dirEntries)` of an array of `DirectoryEntry` for each entry in the directory if successful or `Err(exception)` otherwise
|
|
1159
1041
|
*/
|
|
1160
|
-
|
|
1042
|
+
@unsafe
|
|
1043
|
+
export let fdReaddir = (fd: FileDescriptor) => {
|
|
1161
1044
|
let fdArg = fd
|
|
1162
1045
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1163
1046
|
|
|
@@ -1170,17 +1053,17 @@ export let rec fdReaddir = (fd: FileDescriptor) => {
|
|
|
1170
1053
|
let mut bufLen = structWidth
|
|
1171
1054
|
|
|
1172
1055
|
let err = Wasi.fd_readdir(fd, buf, bufLen, cookie, bufUsed)
|
|
1173
|
-
|
|
1056
|
+
if (err != Wasi._ESUCCESS) {
|
|
1174
1057
|
Memory.free(buf)
|
|
1175
1058
|
Memory.free(bufUsed)
|
|
1176
|
-
|
|
1059
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1177
1060
|
} else {
|
|
1178
1061
|
let used = WasmI32.load(bufUsed, 0n)
|
|
1179
1062
|
|
|
1180
1063
|
if (used <= 0n) {
|
|
1181
1064
|
Memory.free(buf)
|
|
1182
1065
|
Memory.free(bufUsed)
|
|
1183
|
-
|
|
1066
|
+
Ok(WasmI32.toGrain(allocateArray(0n)): Array<DirectoryEntry>)
|
|
1184
1067
|
} else {
|
|
1185
1068
|
bufLen = WasmI32.load(buf, 16n) + structWidth * 2n
|
|
1186
1069
|
|
|
@@ -1256,14 +1139,11 @@ export let rec fdReaddir = (fd: FileDescriptor) => {
|
|
|
1256
1139
|
bufs = next
|
|
1257
1140
|
}
|
|
1258
1141
|
|
|
1259
|
-
|
|
1142
|
+
Ok(WasmI32.toGrain(arr): Array<DirectoryEntry>)
|
|
1260
1143
|
},
|
|
1261
1144
|
}
|
|
1262
1145
|
}
|
|
1263
1146
|
}
|
|
1264
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1265
|
-
Memory.decRef(WasmI32.fromGrain(fdReaddir))
|
|
1266
|
-
ret
|
|
1267
1147
|
}
|
|
1268
1148
|
|
|
1269
1149
|
/**
|
|
@@ -1273,7 +1153,8 @@ export let rec fdReaddir = (fd: FileDescriptor) => {
|
|
|
1273
1153
|
* @param toFd: The file descriptor to overwrite
|
|
1274
1154
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1275
1155
|
*/
|
|
1276
|
-
|
|
1156
|
+
@unsafe
|
|
1157
|
+
export let fdRenumber = (fromFd: FileDescriptor, toFd: FileDescriptor) => {
|
|
1277
1158
|
let fromFdArg = fromFd
|
|
1278
1159
|
let toFdArg = toFd
|
|
1279
1160
|
let fromFd = match (fromFd) {
|
|
@@ -1283,15 +1164,11 @@ export let rec fdRenumber = (fromFd: FileDescriptor, toFd: FileDescriptor) => {
|
|
|
1283
1164
|
let toFd = match (toFd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1284
1165
|
|
|
1285
1166
|
let err = Wasi.fd_renumber(fromFd, toFd)
|
|
1286
|
-
|
|
1287
|
-
|
|
1167
|
+
if (err != Wasi._ESUCCESS) {
|
|
1168
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1288
1169
|
} else {
|
|
1289
|
-
|
|
1170
|
+
Ok(void)
|
|
1290
1171
|
}
|
|
1291
|
-
Memory.decRef(WasmI32.fromGrain(fromFdArg))
|
|
1292
|
-
Memory.decRef(WasmI32.fromGrain(toFdArg))
|
|
1293
|
-
Memory.decRef(WasmI32.fromGrain(fdRenumber))
|
|
1294
|
-
ret
|
|
1295
1172
|
}
|
|
1296
1173
|
|
|
1297
1174
|
/**
|
|
@@ -1302,7 +1179,8 @@ export let rec fdRenumber = (fromFd: FileDescriptor, toFd: FileDescriptor) => {
|
|
|
1302
1179
|
* @param whence: The location from which the offset is relative
|
|
1303
1180
|
* @returns `Ok(offset)` of the new offset of the file descriptor, relative to the start of the file, if successful or `Err(exception)` otherwise
|
|
1304
1181
|
*/
|
|
1305
|
-
|
|
1182
|
+
@unsafe
|
|
1183
|
+
export let fdSeek = (fd: FileDescriptor, offset: Int64, whence: Whence) => {
|
|
1306
1184
|
let fdArg = fd
|
|
1307
1185
|
let offsetArg = offset
|
|
1308
1186
|
let whenceArg = whence
|
|
@@ -1320,17 +1198,12 @@ export let rec fdSeek = (fd: FileDescriptor, offset: Int64, whence: Whence) => {
|
|
|
1320
1198
|
let newoffsetPtr = newoffset + 8n
|
|
1321
1199
|
|
|
1322
1200
|
let err = Wasi.fd_seek(fd, offset, whence, newoffsetPtr)
|
|
1323
|
-
|
|
1201
|
+
if (err != Wasi._ESUCCESS) {
|
|
1324
1202
|
Memory.free(newoffset)
|
|
1325
|
-
|
|
1203
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1326
1204
|
} else {
|
|
1327
|
-
|
|
1205
|
+
Ok(WasmI32.toGrain(newoffset): Int64)
|
|
1328
1206
|
}
|
|
1329
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1330
|
-
Memory.decRef(WasmI32.fromGrain(offsetArg))
|
|
1331
|
-
Memory.decRef(WasmI32.fromGrain(whenceArg))
|
|
1332
|
-
Memory.decRef(WasmI32.fromGrain(fdSeek))
|
|
1333
|
-
ret
|
|
1334
1207
|
}
|
|
1335
1208
|
|
|
1336
1209
|
/**
|
|
@@ -1339,7 +1212,8 @@ export let rec fdSeek = (fd: FileDescriptor, offset: Int64, whence: Whence) => {
|
|
|
1339
1212
|
* @param fd: The file descriptor to read the offset
|
|
1340
1213
|
* @returns `Ok(offset)` of the offset of the file descriptor, relative to the start of the file, if successful or `Err(exception)` otherwise
|
|
1341
1214
|
*/
|
|
1342
|
-
|
|
1215
|
+
@unsafe
|
|
1216
|
+
export let fdTell = (fd: FileDescriptor) => {
|
|
1343
1217
|
let fdArg = fd
|
|
1344
1218
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1345
1219
|
|
|
@@ -1347,15 +1221,12 @@ export let rec fdTell = (fd: FileDescriptor) => {
|
|
|
1347
1221
|
let offsetPtr = offset + 8n
|
|
1348
1222
|
|
|
1349
1223
|
let err = Wasi.fd_tell(fd, offsetPtr)
|
|
1350
|
-
|
|
1224
|
+
if (err != Wasi._ESUCCESS) {
|
|
1351
1225
|
Memory.free(offset)
|
|
1352
|
-
|
|
1226
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1353
1227
|
} else {
|
|
1354
|
-
|
|
1228
|
+
Ok(WasmI32.toGrain(offset): Int64)
|
|
1355
1229
|
}
|
|
1356
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1357
|
-
Memory.decRef(WasmI32.fromGrain(fdTell))
|
|
1358
|
-
ret
|
|
1359
1230
|
}
|
|
1360
1231
|
|
|
1361
1232
|
/**
|
|
@@ -1365,7 +1236,8 @@ export let rec fdTell = (fd: FileDescriptor) => {
|
|
|
1365
1236
|
* @param path: The path to the new directory
|
|
1366
1237
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1367
1238
|
*/
|
|
1368
|
-
|
|
1239
|
+
@unsafe
|
|
1240
|
+
export let pathCreateDirectory = (fd: FileDescriptor, path: String) => {
|
|
1369
1241
|
let fdArg = fd
|
|
1370
1242
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1371
1243
|
|
|
@@ -1374,15 +1246,11 @@ export let rec pathCreateDirectory = (fd: FileDescriptor, path: String) => {
|
|
|
1374
1246
|
let size = WasmI32.load(stringPtr, 4n)
|
|
1375
1247
|
|
|
1376
1248
|
let err = Wasi.path_create_directory(fd, stringPtr + 8n, size)
|
|
1377
|
-
|
|
1378
|
-
|
|
1249
|
+
if (err != Wasi._ESUCCESS) {
|
|
1250
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1379
1251
|
} else {
|
|
1380
|
-
|
|
1252
|
+
Ok(void)
|
|
1381
1253
|
}
|
|
1382
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1383
|
-
Memory.decRef(WasmI32.fromGrain(path))
|
|
1384
|
-
Memory.decRef(WasmI32.fromGrain(pathCreateDirectory))
|
|
1385
|
-
ret
|
|
1386
1254
|
}
|
|
1387
1255
|
|
|
1388
1256
|
/**
|
|
@@ -1393,7 +1261,8 @@ export let rec pathCreateDirectory = (fd: FileDescriptor, path: String) => {
|
|
|
1393
1261
|
* @param path: The path to retrieve information about
|
|
1394
1262
|
* @returns `Ok(info)` of the `Filestats` associated with the file descriptor if successful or `Err(exception)` otherwise
|
|
1395
1263
|
*/
|
|
1396
|
-
|
|
1264
|
+
@unsafe
|
|
1265
|
+
export let pathFilestats =
|
|
1397
1266
|
(
|
|
1398
1267
|
fd: FileDescriptor,
|
|
1399
1268
|
dirFlags: List<LookupFlag>,
|
|
@@ -1417,9 +1286,9 @@ export let rec pathFilestats =
|
|
|
1417
1286
|
pathSize,
|
|
1418
1287
|
filestats
|
|
1419
1288
|
)
|
|
1420
|
-
|
|
1289
|
+
if (err != Wasi._ESUCCESS) {
|
|
1421
1290
|
Memory.free(filestats)
|
|
1422
|
-
|
|
1291
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1423
1292
|
} else {
|
|
1424
1293
|
let device = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 0n))): Int64
|
|
1425
1294
|
let inode = WasmI32.toGrain(newInt64(WasmI64.load(filestats, 8n))): Int64
|
|
@@ -1438,15 +1307,10 @@ export let rec pathFilestats =
|
|
|
1438
1307
|
|
|
1439
1308
|
Memory.free(filestats)
|
|
1440
1309
|
|
|
1441
|
-
|
|
1310
|
+
Ok(
|
|
1442
1311
|
{ device, inode, filetype, linkcount, size, accessed, modified, changed }
|
|
1443
1312
|
)
|
|
1444
1313
|
}
|
|
1445
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1446
|
-
Memory.decRef(WasmI32.fromGrain(dirFlags))
|
|
1447
|
-
Memory.decRef(WasmI32.fromGrain(path))
|
|
1448
|
-
Memory.decRef(WasmI32.fromGrain(pathFilestats))
|
|
1449
|
-
ret
|
|
1450
1314
|
}
|
|
1451
1315
|
|
|
1452
1316
|
/**
|
|
@@ -1458,7 +1322,8 @@ export let rec pathFilestats =
|
|
|
1458
1322
|
* @param timestamp: The time to set
|
|
1459
1323
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1460
1324
|
*/
|
|
1461
|
-
|
|
1325
|
+
@unsafe
|
|
1326
|
+
export let pathSetAccessTime =
|
|
1462
1327
|
(
|
|
1463
1328
|
fd: FileDescriptor,
|
|
1464
1329
|
dirFlags: List<LookupFlag>,
|
|
@@ -1485,17 +1350,11 @@ export let rec pathSetAccessTime =
|
|
|
1485
1350
|
0N,
|
|
1486
1351
|
Wasi._TIME_SET_ATIM
|
|
1487
1352
|
)
|
|
1488
|
-
|
|
1489
|
-
|
|
1353
|
+
if (err != Wasi._ESUCCESS) {
|
|
1354
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1490
1355
|
} else {
|
|
1491
|
-
|
|
1356
|
+
Ok(void)
|
|
1492
1357
|
}
|
|
1493
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1494
|
-
Memory.decRef(WasmI32.fromGrain(dirFlags))
|
|
1495
|
-
Memory.decRef(WasmI32.fromGrain(path))
|
|
1496
|
-
Memory.decRef(WasmI32.fromGrain(timestamp))
|
|
1497
|
-
Memory.decRef(WasmI32.fromGrain(pathSetAccessTime))
|
|
1498
|
-
ret
|
|
1499
1358
|
}
|
|
1500
1359
|
|
|
1501
1360
|
/**
|
|
@@ -1506,6 +1365,7 @@ export let rec pathSetAccessTime =
|
|
|
1506
1365
|
* @param path: The path to set the time
|
|
1507
1366
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1508
1367
|
*/
|
|
1368
|
+
@unsafe
|
|
1509
1369
|
export let pathSetAccessTimeNow =
|
|
1510
1370
|
(
|
|
1511
1371
|
fd: FileDescriptor,
|
|
@@ -1530,16 +1390,11 @@ export let pathSetAccessTimeNow =
|
|
|
1530
1390
|
0N,
|
|
1531
1391
|
Wasi._TIME_SET_ATIM_NOW
|
|
1532
1392
|
)
|
|
1533
|
-
|
|
1534
|
-
|
|
1393
|
+
if (err != Wasi._ESUCCESS) {
|
|
1394
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1535
1395
|
} else {
|
|
1536
|
-
|
|
1396
|
+
Ok(void)
|
|
1537
1397
|
}
|
|
1538
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1539
|
-
Memory.decRef(WasmI32.fromGrain(dirFlags))
|
|
1540
|
-
Memory.decRef(WasmI32.fromGrain(path))
|
|
1541
|
-
Memory.decRef(WasmI32.fromGrain(pathSetAccessTime))
|
|
1542
|
-
ret
|
|
1543
1398
|
}
|
|
1544
1399
|
|
|
1545
1400
|
/**
|
|
@@ -1551,7 +1406,8 @@ export let pathSetAccessTimeNow =
|
|
|
1551
1406
|
* @param timestamp: The time to set
|
|
1552
1407
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1553
1408
|
*/
|
|
1554
|
-
|
|
1409
|
+
@unsafe
|
|
1410
|
+
export let pathSetModifiedTime =
|
|
1555
1411
|
(
|
|
1556
1412
|
fd: FileDescriptor,
|
|
1557
1413
|
dirFlags: List<LookupFlag>,
|
|
@@ -1578,17 +1434,11 @@ export let rec pathSetModifiedTime =
|
|
|
1578
1434
|
time,
|
|
1579
1435
|
Wasi._TIME_SET_MTIM
|
|
1580
1436
|
)
|
|
1581
|
-
|
|
1582
|
-
|
|
1437
|
+
if (err != Wasi._ESUCCESS) {
|
|
1438
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1583
1439
|
} else {
|
|
1584
|
-
|
|
1440
|
+
Ok(void)
|
|
1585
1441
|
}
|
|
1586
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1587
|
-
Memory.decRef(WasmI32.fromGrain(dirFlags))
|
|
1588
|
-
Memory.decRef(WasmI32.fromGrain(path))
|
|
1589
|
-
Memory.decRef(WasmI32.fromGrain(timestamp))
|
|
1590
|
-
Memory.decRef(WasmI32.fromGrain(pathSetModifiedTime))
|
|
1591
|
-
ret
|
|
1592
1442
|
}
|
|
1593
1443
|
|
|
1594
1444
|
/**
|
|
@@ -1599,7 +1449,8 @@ export let rec pathSetModifiedTime =
|
|
|
1599
1449
|
* @param path: The path to set the time
|
|
1600
1450
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1601
1451
|
*/
|
|
1602
|
-
|
|
1452
|
+
@unsafe
|
|
1453
|
+
export let pathSetModifiedTimeNow =
|
|
1603
1454
|
(
|
|
1604
1455
|
fd: FileDescriptor,
|
|
1605
1456
|
dirFlags: List<LookupFlag>,
|
|
@@ -1623,16 +1474,11 @@ export let rec pathSetModifiedTimeNow =
|
|
|
1623
1474
|
0N,
|
|
1624
1475
|
Wasi._TIME_SET_MTIM_NOW
|
|
1625
1476
|
)
|
|
1626
|
-
|
|
1627
|
-
|
|
1477
|
+
if (err != Wasi._ESUCCESS) {
|
|
1478
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1628
1479
|
} else {
|
|
1629
|
-
|
|
1480
|
+
Ok(void)
|
|
1630
1481
|
}
|
|
1631
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1632
|
-
Memory.decRef(WasmI32.fromGrain(dirFlags))
|
|
1633
|
-
Memory.decRef(WasmI32.fromGrain(path))
|
|
1634
|
-
Memory.decRef(WasmI32.fromGrain(pathSetModifiedTimeNow))
|
|
1635
|
-
ret
|
|
1636
1482
|
}
|
|
1637
1483
|
|
|
1638
1484
|
/**
|
|
@@ -1645,7 +1491,8 @@ export let rec pathSetModifiedTimeNow =
|
|
|
1645
1491
|
* @param targetPath: The path to the target of the link
|
|
1646
1492
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1647
1493
|
*/
|
|
1648
|
-
|
|
1494
|
+
@unsafe
|
|
1495
|
+
export let pathLink =
|
|
1649
1496
|
(
|
|
1650
1497
|
sourceFd: FileDescriptor,
|
|
1651
1498
|
dirFlags: List<LookupFlag>,
|
|
@@ -1680,18 +1527,11 @@ export let rec pathLink =
|
|
|
1680
1527
|
targetPtr + 8n,
|
|
1681
1528
|
targetSize
|
|
1682
1529
|
)
|
|
1683
|
-
|
|
1684
|
-
|
|
1530
|
+
if (err != Wasi._ESUCCESS) {
|
|
1531
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1685
1532
|
} else {
|
|
1686
|
-
|
|
1533
|
+
Ok(void)
|
|
1687
1534
|
}
|
|
1688
|
-
Memory.decRef(WasmI32.fromGrain(sourceFdArg))
|
|
1689
|
-
Memory.decRef(WasmI32.fromGrain(dirFlags))
|
|
1690
|
-
Memory.decRef(WasmI32.fromGrain(sourcePath))
|
|
1691
|
-
Memory.decRef(WasmI32.fromGrain(targetFdArg))
|
|
1692
|
-
Memory.decRef(WasmI32.fromGrain(targetPath))
|
|
1693
|
-
Memory.decRef(WasmI32.fromGrain(pathLink))
|
|
1694
|
-
ret
|
|
1695
1535
|
}
|
|
1696
1536
|
|
|
1697
1537
|
/**
|
|
@@ -1702,7 +1542,8 @@ export let rec pathLink =
|
|
|
1702
1542
|
* @param targetPath: The path to the target of the link
|
|
1703
1543
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1704
1544
|
*/
|
|
1705
|
-
|
|
1545
|
+
@unsafe
|
|
1546
|
+
export let pathSymlink =
|
|
1706
1547
|
(
|
|
1707
1548
|
fd: FileDescriptor,
|
|
1708
1549
|
sourcePath: String,
|
|
@@ -1724,16 +1565,11 @@ export let rec pathSymlink =
|
|
|
1724
1565
|
targetPtr + 8n,
|
|
1725
1566
|
targetSize
|
|
1726
1567
|
)
|
|
1727
|
-
|
|
1728
|
-
|
|
1568
|
+
if (err != Wasi._ESUCCESS) {
|
|
1569
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1729
1570
|
} else {
|
|
1730
|
-
|
|
1571
|
+
Ok(void)
|
|
1731
1572
|
}
|
|
1732
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1733
|
-
Memory.decRef(WasmI32.fromGrain(sourcePath))
|
|
1734
|
-
Memory.decRef(WasmI32.fromGrain(targetPath))
|
|
1735
|
-
Memory.decRef(WasmI32.fromGrain(pathSymlink))
|
|
1736
|
-
ret
|
|
1737
1573
|
}
|
|
1738
1574
|
|
|
1739
1575
|
/**
|
|
@@ -1743,7 +1579,8 @@ export let rec pathSymlink =
|
|
|
1743
1579
|
* @param path: The path of the file to unlink
|
|
1744
1580
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1745
1581
|
*/
|
|
1746
|
-
|
|
1582
|
+
@unsafe
|
|
1583
|
+
export let pathUnlink = (fd: FileDescriptor, path: String) => {
|
|
1747
1584
|
let fdArg = fd
|
|
1748
1585
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1749
1586
|
|
|
@@ -1751,15 +1588,11 @@ export let rec pathUnlink = (fd: FileDescriptor, path: String) => {
|
|
|
1751
1588
|
let pathSize = WasmI32.load(pathPtr, 4n)
|
|
1752
1589
|
|
|
1753
1590
|
let err = Wasi.path_unlink_file(fd, pathPtr + 8n, pathSize)
|
|
1754
|
-
|
|
1755
|
-
|
|
1591
|
+
if (err != Wasi._ESUCCESS) {
|
|
1592
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1756
1593
|
} else {
|
|
1757
|
-
|
|
1594
|
+
Ok(void)
|
|
1758
1595
|
}
|
|
1759
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1760
|
-
Memory.decRef(WasmI32.fromGrain(path))
|
|
1761
|
-
Memory.decRef(WasmI32.fromGrain(pathUnlink))
|
|
1762
|
-
ret
|
|
1763
1596
|
}
|
|
1764
1597
|
|
|
1765
1598
|
/**
|
|
@@ -1770,12 +1603,8 @@ export let rec pathUnlink = (fd: FileDescriptor, path: String) => {
|
|
|
1770
1603
|
* @param size: The number of bytes to read
|
|
1771
1604
|
* @returns `Ok((contents, numBytes))` of the bytes read and the number of bytes read if successful or `Err(exception)` otherwise
|
|
1772
1605
|
*/
|
|
1773
|
-
|
|
1774
|
-
|
|
1775
|
-
fd: FileDescriptor,
|
|
1776
|
-
path: String,
|
|
1777
|
-
size: Number,
|
|
1778
|
-
) => {
|
|
1606
|
+
@unsafe
|
|
1607
|
+
export let pathReadlink = (fd: FileDescriptor, path: String, size: Number) => {
|
|
1779
1608
|
let fdArg = fd
|
|
1780
1609
|
let sizeArg = size
|
|
1781
1610
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
@@ -1791,21 +1620,16 @@ export let rec pathReadlink =
|
|
|
1791
1620
|
let nread = Memory.malloc(4n)
|
|
1792
1621
|
|
|
1793
1622
|
let err = Wasi.path_readlink(fd, pathPtr, pathSize + 8n, strPtr, size, nread)
|
|
1794
|
-
|
|
1623
|
+
if (err != Wasi._ESUCCESS) {
|
|
1795
1624
|
Memory.free(grainStrPtr)
|
|
1796
1625
|
Memory.free(nread)
|
|
1797
|
-
|
|
1626
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1798
1627
|
} else {
|
|
1799
1628
|
let read = tagSimpleNumber(WasmI32.load(nread, 0n))
|
|
1800
1629
|
Memory.free(nread)
|
|
1801
1630
|
|
|
1802
|
-
|
|
1631
|
+
Ok((WasmI32.toGrain(grainStrPtr): String, read))
|
|
1803
1632
|
}
|
|
1804
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1805
|
-
Memory.decRef(WasmI32.fromGrain(path))
|
|
1806
|
-
Memory.decRef(WasmI32.fromGrain(sizeArg))
|
|
1807
|
-
Memory.decRef(WasmI32.fromGrain(pathReadlink))
|
|
1808
|
-
ret
|
|
1809
1633
|
}
|
|
1810
1634
|
|
|
1811
1635
|
/**
|
|
@@ -1815,7 +1639,8 @@ export let rec pathReadlink =
|
|
|
1815
1639
|
* @param path: The path to the directory to remove
|
|
1816
1640
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1817
1641
|
*/
|
|
1818
|
-
|
|
1642
|
+
@unsafe
|
|
1643
|
+
export let pathRemoveDirectory = (fd: FileDescriptor, path: String) => {
|
|
1819
1644
|
let fdArg = fd
|
|
1820
1645
|
let fd = match (fd) { FileDescriptor(n) => WasmI32.fromGrain(n) >> 1n }
|
|
1821
1646
|
|
|
@@ -1823,15 +1648,11 @@ export let rec pathRemoveDirectory = (fd: FileDescriptor, path: String) => {
|
|
|
1823
1648
|
let pathSize = WasmI32.load(pathPtr, 4n)
|
|
1824
1649
|
|
|
1825
1650
|
let err = Wasi.path_remove_directory(fd, pathPtr + 8n, pathSize)
|
|
1826
|
-
|
|
1827
|
-
|
|
1651
|
+
if (err != Wasi._ESUCCESS) {
|
|
1652
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1828
1653
|
} else {
|
|
1829
|
-
|
|
1654
|
+
Ok(void)
|
|
1830
1655
|
}
|
|
1831
|
-
Memory.decRef(WasmI32.fromGrain(fdArg))
|
|
1832
|
-
Memory.decRef(WasmI32.fromGrain(path))
|
|
1833
|
-
Memory.decRef(WasmI32.fromGrain(pathRemoveDirectory))
|
|
1834
|
-
ret
|
|
1835
1656
|
}
|
|
1836
1657
|
|
|
1837
1658
|
/**
|
|
@@ -1843,7 +1664,8 @@ export let rec pathRemoveDirectory = (fd: FileDescriptor, path: String) => {
|
|
|
1843
1664
|
* @param targetPath: The new path of the file
|
|
1844
1665
|
* @returns `Ok(void)` if successful or `Err(exception)` otherwise
|
|
1845
1666
|
*/
|
|
1846
|
-
|
|
1667
|
+
@unsafe
|
|
1668
|
+
export let pathRename =
|
|
1847
1669
|
(
|
|
1848
1670
|
sourceFd: FileDescriptor,
|
|
1849
1671
|
sourcePath: String,
|
|
@@ -1874,15 +1696,9 @@ export let rec pathRename =
|
|
|
1874
1696
|
targetPtr + 8n,
|
|
1875
1697
|
targetSize
|
|
1876
1698
|
)
|
|
1877
|
-
|
|
1878
|
-
|
|
1699
|
+
if (err != Wasi._ESUCCESS) {
|
|
1700
|
+
Err(Wasi.SystemError(tagSimpleNumber(err)))
|
|
1879
1701
|
} else {
|
|
1880
|
-
|
|
1702
|
+
Ok(void)
|
|
1881
1703
|
}
|
|
1882
|
-
Memory.decRef(WasmI32.fromGrain(sourceFdArg))
|
|
1883
|
-
Memory.decRef(WasmI32.fromGrain(sourcePath))
|
|
1884
|
-
Memory.decRef(WasmI32.fromGrain(targetFdArg))
|
|
1885
|
-
Memory.decRef(WasmI32.fromGrain(targetPath))
|
|
1886
|
-
Memory.decRef(WasmI32.fromGrain(pathRename))
|
|
1887
|
-
ret
|
|
1888
1704
|
}
|