mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-03 14:18:47 +00:00
Clear up fmt.wprint* length logic
This commit is contained in:
+9
-3
@@ -226,7 +226,9 @@ wprint :: proc(w: io.Writer, args: ..any, sep := " ") -> int {
|
|||||||
fmt_value(&fi, args[i], 'v');
|
fmt_value(&fi, args[i], 'v');
|
||||||
}
|
}
|
||||||
io.flush(auto_cast w);
|
io.flush(auto_cast w);
|
||||||
return int(io.size(auto_cast w) - size0);
|
|
||||||
|
size1 := io.size(auto_cast w);
|
||||||
|
return int(size1 - size0);
|
||||||
}
|
}
|
||||||
|
|
||||||
wprintln :: proc(w: io.Writer, args: ..any, sep := " ") -> int {
|
wprintln :: proc(w: io.Writer, args: ..any, sep := " ") -> int {
|
||||||
@@ -244,7 +246,9 @@ wprintln :: proc(w: io.Writer, args: ..any, sep := " ") -> int {
|
|||||||
}
|
}
|
||||||
io.write_byte(fi.writer, '\n');
|
io.write_byte(fi.writer, '\n');
|
||||||
io.flush(auto_cast w);
|
io.flush(auto_cast w);
|
||||||
return int(io.size(auto_cast w) - size0);
|
|
||||||
|
size1 := io.size(auto_cast w);
|
||||||
|
return int(size1 - size0);
|
||||||
}
|
}
|
||||||
|
|
||||||
wprintf :: proc(w: io.Writer, fmt: string, args: ..any) -> int {
|
wprintf :: proc(w: io.Writer, fmt: string, args: ..any) -> int {
|
||||||
@@ -521,7 +525,9 @@ wprintf :: proc(w: io.Writer, fmt: string, args: ..any) -> int {
|
|||||||
}
|
}
|
||||||
|
|
||||||
io.flush(auto_cast w);
|
io.flush(auto_cast w);
|
||||||
return int(io.size(auto_cast w) - size0);
|
|
||||||
|
size1 := io.size(auto_cast w);
|
||||||
|
return int(size1 - size0);
|
||||||
}
|
}
|
||||||
|
|
||||||
wprint_type :: proc(w: io.Writer, info: ^runtime.Type_Info) -> int {
|
wprint_type :: proc(w: io.Writer, info: ^runtime.Type_Info) -> int {
|
||||||
|
|||||||
@@ -362,9 +362,9 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
|
|||||||
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
file_size :: proc(fd: Handle) -> (i64, Errno) {
|
||||||
s, err := _fstat(fd);
|
s, err := _fstat(fd);
|
||||||
if err != ERROR_NONE {
|
if err != ERROR_NONE {
|
||||||
return -1, err;
|
return 0, err;
|
||||||
}
|
}
|
||||||
return s.size, ERROR_NONE;
|
return max(s.size, 0), ERROR_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -459,7 +459,7 @@ _rewinddir :: inline proc(dirp: Dir) {
|
|||||||
_readdir :: inline proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool) {
|
_readdir :: inline proc(dirp: Dir) -> (entry: Dirent, err: Errno, end_of_stream: bool) {
|
||||||
result: ^Dirent;
|
result: ^Dirent;
|
||||||
rc := _unix_readdir_r(dirp, &entry, &result);
|
rc := _unix_readdir_r(dirp, &entry, &result);
|
||||||
|
|
||||||
if rc != 0 {
|
if rc != 0 {
|
||||||
err = Errno(get_last_error());
|
err = Errno(get_last_error());
|
||||||
return;
|
return;
|
||||||
@@ -502,9 +502,9 @@ absolute_path_from_handle :: proc(fd: Handle) -> (string, Errno) {
|
|||||||
buf : [256]byte;
|
buf : [256]byte;
|
||||||
fd_str := strconv.itoa( buf[:], cast(int)fd );
|
fd_str := strconv.itoa( buf[:], cast(int)fd );
|
||||||
|
|
||||||
procfs_path := strings.concatenate( []string{ "/proc/self/fd/", fd_str } );
|
procfs_path := strings.concatenate( []string{ "/proc/self/fd/", fd_str } );
|
||||||
defer delete(procfs_path);
|
defer delete(procfs_path);
|
||||||
|
|
||||||
return _readlink(procfs_path);
|
return _readlink(procfs_path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user