diff options
| -rw-r--r-- | internal/c_wrap_linux.tnsl | 3 | ||||
| -rw-r--r-- | io/file.tnsl | 8 | ||||
| -rw-r--r-- | io/io.tnsl | 1 | ||||
| -rw-r--r-- | io/path.tnsl | 10 |
4 files changed, 14 insertions, 8 deletions
diff --git a/internal/c_wrap_linux.tnsl b/internal/c_wrap_linux.tnsl index 6c3f27e..eb16a9a 100644 --- a/internal/c_wrap_linux.tnsl +++ b/internal/c_wrap_linux.tnsl @@ -261,9 +261,8 @@ asm "extern malloc, realloc, free, printf, putchar, open, close, read, write, ls asm "sub rsp, 128" # Call libc - asm "mov rdi, r10" # handle + asm "mov rdi, r10" # path name asm "mov rsi, 0" # resolved_path - asm "mov rdx, 1" # one byte asm "call realpath wrt ..plt" asm "mov r11, rax" diff --git a/io/file.tnsl b/io/file.tnsl index 83e9d0d..5dffeaa 100644 --- a/io/file.tnsl +++ b/io/file.tnsl @@ -13,7 +13,6 @@ struct File { self.path.init(str) self.handle = -1 self.at_end = false - self.pos = 0 ;/ /; relative (~uint8 path) [File] @@ -41,6 +40,8 @@ struct File { /; if (self.handle + 1 == 0) self.at_end = true + ;; else + self.pos = 0 ;/ _delete(p) ;/ @@ -50,6 +51,8 @@ struct File { self.handle = _create_file(p) /; if (self.handle + 1 == 0) self.at_end = true + ;; else + self.pos = 0 ;/ _delete(p) ;/ @@ -57,8 +60,7 @@ struct File { /; close /; if (self.handle + 1 !== 0) _close_file(self.handle) - self.handle = 0 - self.handle-- + self.handle = -1 self.at_end = false ;/ ;/ @@ -1,5 +1,6 @@ /; module io import "file.tnsl" + import "path.tnsl" ;/ diff --git a/io/path.tnsl b/io/path.tnsl index 5a71403..13fc574 100644 --- a/io/path.tnsl +++ b/io/path.tnsl @@ -12,6 +12,9 @@ uint8 PATH_SEP = '/' self.strings.init(8) ~uint8 real = _realpath(path) + /; if (real == null) + return + ;/ box.List tmp tmp.init(1) @@ -45,13 +48,13 @@ uint8 PATH_SEP = '/' return out.as_cstr() ;/ - ~uint8 str = self.strings.get(0) - out.push_cstr(str) + ~~uint8 str = self.strings.get(0) + out.push_cstr(str`) /; loop (int i = 1; i < self.strings.count) [i++] str = self.strings.get(i) out.push(~PATH_SEP) - out.push_cstr(str) + out.push_cstr(str`) ;/ return out.as_cstr() @@ -88,6 +91,7 @@ uint8 PATH_SEP = '/' Path out out.init(full) + return out ;/ /; end |