mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Add #caller_location to os2.read_entire_file
This commit is contained in:
@@ -107,17 +107,14 @@ read_entire_file :: proc{
|
|||||||
}
|
}
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
read_entire_file_from_path :: proc(name: string, allocator: runtime.Allocator) -> (data: []byte, err: Error) {
|
read_entire_file_from_path :: proc(name: string, allocator: runtime.Allocator, loc := #caller_location) -> (data: []byte, err: Error) {
|
||||||
f, ferr := open(name)
|
f := open(name) or_return
|
||||||
if ferr != nil {
|
|
||||||
return nil, ferr
|
|
||||||
}
|
|
||||||
defer close(f)
|
defer close(f)
|
||||||
return read_entire_file_from_file(f, allocator)
|
return read_entire_file_from_file(f, allocator, loc)
|
||||||
}
|
}
|
||||||
|
|
||||||
@(require_results)
|
@(require_results)
|
||||||
read_entire_file_from_file :: proc(f: ^File, allocator: runtime.Allocator) -> (data: []byte, err: Error) {
|
read_entire_file_from_file :: proc(f: ^File, allocator: runtime.Allocator, loc := #caller_location) -> (data: []byte, err: Error) {
|
||||||
size: int
|
size: int
|
||||||
has_size := false
|
has_size := false
|
||||||
if size64, serr := file_size(f); serr == nil {
|
if size64, serr := file_size(f); serr == nil {
|
||||||
@@ -129,7 +126,7 @@ read_entire_file_from_file :: proc(f: ^File, allocator: runtime.Allocator) -> (d
|
|||||||
|
|
||||||
if has_size && size > 0 {
|
if has_size && size > 0 {
|
||||||
total: int
|
total: int
|
||||||
data = make([]byte, size, allocator) or_return
|
data = make([]byte, size, allocator, loc) or_return
|
||||||
for total < len(data) {
|
for total < len(data) {
|
||||||
n: int
|
n: int
|
||||||
n, err = read(f, data[total:])
|
n, err = read(f, data[total:])
|
||||||
@@ -145,13 +142,13 @@ read_entire_file_from_file :: proc(f: ^File, allocator: runtime.Allocator) -> (d
|
|||||||
return
|
return
|
||||||
} else {
|
} else {
|
||||||
buffer: [1024]u8
|
buffer: [1024]u8
|
||||||
out_buffer := make([dynamic]u8, 0, 0, allocator)
|
out_buffer := make([dynamic]u8, 0, 0, allocator, loc)
|
||||||
total := 0
|
total := 0
|
||||||
for {
|
for {
|
||||||
n: int
|
n: int
|
||||||
n, err = read(f, buffer[:])
|
n, err = read(f, buffer[:])
|
||||||
total += n
|
total += n
|
||||||
append_elems(&out_buffer, ..buffer[:n]) or_return
|
append_elems(&out_buffer, ..buffer[:n], loc=loc) or_return
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if err == .EOF || err == .Broken_Pipe {
|
if err == .EOF || err == .Broken_Pipe {
|
||||||
err = nil
|
err = nil
|
||||||
|
|||||||
Reference in New Issue
Block a user