37 lines
653 B
Odin
37 lines
653 B
Odin
package physfs
|
|
|
|
import "core:strings"
|
|
|
|
read_entire_file :: proc(
|
|
path: string,
|
|
allocator := context.allocator,
|
|
) -> (
|
|
data: []byte,
|
|
err: ErrorCode,
|
|
) {
|
|
pathc := strings.clone_to_cstring(path, context.temp_allocator)
|
|
file := openRead(pathc)
|
|
if file == nil {
|
|
return nil, getLastErrorCode()
|
|
}
|
|
defer close(file)
|
|
|
|
size := fileLength(file)
|
|
if size == -1 {
|
|
return nil, getLastErrorCode()
|
|
}
|
|
|
|
if size == 0 {
|
|
return nil, .OK
|
|
}
|
|
|
|
data = make([]byte, int(size), allocator)
|
|
bytes_read := readBytes(file, raw_data(data), u64(size))
|
|
if bytes_read != size {
|
|
delete_slice(data, allocator)
|
|
return nil, getLastErrorCode()
|
|
}
|
|
|
|
return data, .OK
|
|
}
|