aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-02-11 10:44:38 +0000
committergingerBill <bill@gingerbill.org>2021-02-11 10:44:38 +0000
commitd5dfa14f184793ebfcb3365be9c682018ef7e73a (patch)
tree383681d7bdadfc9d4df8fdfce698e95f35887e6b
parentfa02dc97367fed2b487f53877ce3879d1769682b (diff)
Clear up fmt.wprint* length logic
-rw-r--r--core/fmt/fmt.odin12
-rw-r--r--core/os/os_linux.odin10
2 files changed, 14 insertions, 8 deletions
diff --git a/core/fmt/fmt.odin b/core/fmt/fmt.odin
index 81fa8b2e8..3f258f15a 100644
--- a/core/fmt/fmt.odin
+++ b/core/fmt/fmt.odin
@@ -226,7 +226,9 @@ wprint :: proc(w: io.Writer, args: ..any, sep := " ") -> int {
fmt_value(&fi, args[i], 'v');
}
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 {
@@ -244,7 +246,9 @@ wprintln :: proc(w: io.Writer, args: ..any, sep := " ") -> int {
}
io.write_byte(fi.writer, '\n');
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 {
@@ -521,7 +525,9 @@ wprintf :: proc(w: io.Writer, fmt: string, args: ..any) -> int {
}
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 {
diff --git a/core/os/os_linux.odin b/core/os/os_linux.odin
index d7cd291e1..517570686 100644
--- a/core/os/os_linux.odin
+++ b/core/os/os_linux.odin
@@ -362,9 +362,9 @@ seek :: proc(fd: Handle, offset: i64, whence: int) -> (i64, Errno) {
file_size :: proc(fd: Handle) -> (i64, Errno) {
s, err := _fstat(fd);
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) {
result: ^Dirent;
rc := _unix_readdir_r(dirp, &entry, &result);
-
+
if rc != 0 {
err = Errno(get_last_error());
return;
@@ -502,9 +502,9 @@ absolute_path_from_handle :: proc(fd: Handle) -> (string, Errno) {
buf : [256]byte;
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);
-
+
return _readlink(procfs_path);
}