mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-24 15:25:20 +00:00
Merge branch 'master' into new-sys-unix
This commit is contained in:
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
20
core/crypto/rand_js.odin
Normal file
20
core/crypto/rand_js.odin
Normal file
@@ -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:]
|
||||
}
|
||||
}
|
||||
14
core/math/rand/system_js.odin
Normal file
14
core/math/rand/system_js.odin
Normal file
@@ -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
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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] == '.' {
|
||||
|
||||
Reference in New Issue
Block a user