mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Move os stuff to OS specific files
This commit is contained in:
@@ -10,7 +10,6 @@ package crypto_hash
|
|||||||
|
|
||||||
import "core:io"
|
import "core:io"
|
||||||
import "core:mem"
|
import "core:mem"
|
||||||
import "core:os"
|
|
||||||
|
|
||||||
// hash_bytes will hash the given input and return the computed digest
|
// hash_bytes will hash the given input and return the computed digest
|
||||||
// in a newly allocated slice.
|
// in a newly allocated slice.
|
||||||
@@ -87,36 +86,3 @@ hash_stream :: proc(
|
|||||||
|
|
||||||
return dst, io.Error.None
|
return dst, io.Error.None
|
||||||
}
|
}
|
||||||
|
|
||||||
// hash_file will read the file provided by the given handle and return the
|
|
||||||
// computed digest in a newly allocated slice.
|
|
||||||
hash_file :: proc(
|
|
||||||
algorithm: Algorithm,
|
|
||||||
hd: os.Handle,
|
|
||||||
load_at_once := false,
|
|
||||||
allocator := context.allocator,
|
|
||||||
) -> (
|
|
||||||
[]byte,
|
|
||||||
io.Error,
|
|
||||||
) {
|
|
||||||
if !load_at_once {
|
|
||||||
return hash_stream(algorithm, os.stream_from_handle(hd), allocator)
|
|
||||||
}
|
|
||||||
|
|
||||||
buf, ok := os.read_entire_file(hd, allocator)
|
|
||||||
if !ok {
|
|
||||||
return nil, io.Error.Unknown
|
|
||||||
}
|
|
||||||
defer delete(buf, allocator)
|
|
||||||
|
|
||||||
return hash_bytes(algorithm, buf, allocator), io.Error.None
|
|
||||||
}
|
|
||||||
|
|
||||||
hash :: proc {
|
|
||||||
hash_stream,
|
|
||||||
hash_file,
|
|
||||||
hash_bytes,
|
|
||||||
hash_string,
|
|
||||||
hash_bytes_to_buffer,
|
|
||||||
hash_string_to_buffer,
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
//+build freestanding
|
||||||
|
package crypto_hash
|
||||||
|
|
||||||
|
hash :: proc {
|
||||||
|
hash_stream,
|
||||||
|
hash_bytes,
|
||||||
|
hash_string,
|
||||||
|
hash_bytes_to_buffer,
|
||||||
|
hash_string_to_buffer,
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
//+build !freestanding
|
||||||
|
package crypto_hash
|
||||||
|
|
||||||
|
import "core:os"
|
||||||
|
|
||||||
|
// hash_file will read the file provided by the given handle and return the
|
||||||
|
// computed digest in a newly allocated slice.
|
||||||
|
hash_file :: proc(
|
||||||
|
algorithm: Algorithm,
|
||||||
|
hd: os.Handle,
|
||||||
|
load_at_once := false,
|
||||||
|
allocator := context.allocator,
|
||||||
|
) -> (
|
||||||
|
[]byte,
|
||||||
|
io.Error,
|
||||||
|
) {
|
||||||
|
if !load_at_once {
|
||||||
|
return hash_stream(algorithm, os.stream_from_handle(hd), allocator)
|
||||||
|
}
|
||||||
|
|
||||||
|
buf, ok := os.read_entire_file(hd, allocator)
|
||||||
|
if !ok {
|
||||||
|
return nil, io.Error.Unknown
|
||||||
|
}
|
||||||
|
defer delete(buf, allocator)
|
||||||
|
|
||||||
|
return hash_bytes(algorithm, buf, allocator), io.Error.None
|
||||||
|
}
|
||||||
|
|
||||||
|
hash :: proc {
|
||||||
|
hash_stream,
|
||||||
|
hash_file,
|
||||||
|
hash_bytes,
|
||||||
|
hash_string,
|
||||||
|
hash_bytes_to_buffer,
|
||||||
|
hash_string_to_buffer,
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user