diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2023-10-31 12:16:25 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-10-31 12:16:25 +0000 |
| commit | eb261f5b28a8d3cddc3dc21441f33775bb3ced95 (patch) | |
| tree | 55014f5e1ffe0c099376699945a1800cc4d16246 /core | |
| parent | bbd4c1054e18f18e934828b5160efce076027d1e (diff) | |
| parent | f5febb633c92ee1cf7b5d88f0146ffac3e2481b7 (diff) | |
Merge branch 'master' into new-sys-unix
Diffstat (limited to 'core')
| -rw-r--r-- | core/crypto/rand_generic.odin | 4 | ||||
| -rw-r--r-- | core/crypto/rand_js.odin | 20 | ||||
| -rw-r--r-- | core/math/rand/system_js.odin | 14 | ||||
| -rw-r--r-- | core/os/os.odin | 4 | ||||
| -rw-r--r-- | core/path/slashpath/path.odin | 6 |
5 files changed, 41 insertions, 7 deletions
diff --git a/core/crypto/rand_generic.odin b/core/crypto/rand_generic.odin index 52abfe4d7..fde91f85a 100644 --- a/core/crypto/rand_generic.odin +++ b/core/crypto/rand_generic.odin @@ -1,7 +1,7 @@ package crypto -when ODIN_OS != .Linux && ODIN_OS != .OpenBSD && ODIN_OS != .Windows { - _rand_bytes :: proc (dst: []byte) { +when ODIN_OS != .Linux && ODIN_OS != .OpenBSD && ODIN_OS != .Windows && ODIN_OS != .JS { + _rand_bytes :: proc(dst: []byte) { unimplemented("crypto: rand_bytes not supported on this OS") } } diff --git a/core/crypto/rand_js.odin b/core/crypto/rand_js.odin new file mode 100644 index 000000000..353b1e6b9 --- /dev/null +++ b/core/crypto/rand_js.odin @@ -0,0 +1,20 @@ +package crypto + +foreign import "odin_env" +foreign odin_env { + @(link_name = "rand_bytes") + env_rand_bytes :: proc "contextless" (buf: []byte) --- +} + +_MAX_PER_CALL_BYTES :: 65536 // 64kiB + +_rand_bytes :: proc(dst: []byte) { + dst := dst + + for len(dst) > 0 { + to_read := min(len(dst), _MAX_PER_CALL_BYTES) + env_rand_bytes(dst[:to_read]) + + dst = dst[to_read:] + } +} diff --git a/core/math/rand/system_js.odin b/core/math/rand/system_js.odin new file mode 100644 index 000000000..b9b71c4a6 --- /dev/null +++ b/core/math/rand/system_js.odin @@ -0,0 +1,14 @@ +package rand + +foreign import "odin_env" +foreign odin_env { + @(link_name = "rand_bytes") + env_rand_bytes :: proc "contextless" (buf: []byte) --- +} + +@(require_results) +_system_random :: proc() -> u64 { + buf: [8]u8 + env_rand_bytes(buf[:]) + return transmute(u64)buf +} diff --git a/core/os/os.odin b/core/os/os.odin index b71ea261e..15864e47e 100644 --- a/core/os/os.odin +++ b/core/os/os.odin @@ -63,8 +63,8 @@ read_at_least :: proc(fd: Handle, buf: []byte, min: int) -> (n: int, err: Errno) if len(buf) < min { return 0, -1 } - for n < min && err == 0 { - nn: int + nn := max(int) + for nn > 0 && n < min && err == 0 { nn, err = read(fd, buf[n:]) n += nn } diff --git a/core/path/slashpath/path.odin b/core/path/slashpath/path.odin index 5f5ab2ae9..ada473c34 100644 --- a/core/path/slashpath/path.odin +++ b/core/path/slashpath/path.odin @@ -159,9 +159,9 @@ join :: proc(elems: []string, allocator := context.allocator) -> string { return ""
}
-// ext returns the file name extension used by "path"
-// The extension is the suffix beginning at the file fot in the last slash separated element of "path"
-// The path is empty if there is no dot
+// ext returns the file name extension used by "path".
+// The extension is the suffix beginning at the dot character in the last slash separated element of "path".
+// The path is empty if there is no dot character.
ext :: proc(path: string, new := false, allocator := context.allocator) -> string {
for i := len(path)-1; i >= 0 && !is_separator(path[i]); i -= 1 {
if path[i] == '.' {
|