From bb7bbcc03386089dce1353e98c071c15c45aa82f Mon Sep 17 00:00:00 2001 From: Kyle Gunger Date: Sat, 30 Mar 2024 04:15:10 -0400 Subject: copy file example --- tnslc/utils/file.tnsl | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'tnslc/utils/file.tnsl') diff --git a/tnslc/utils/file.tnsl b/tnslc/utils/file.tnsl index a33e30c..978f31b 100644 --- a/tnslc/utils/file.tnsl +++ b/tnslc/utils/file.tnsl @@ -5,7 +5,6 @@ struct File { } ~uint8 PT_HANDLE = "Handle: %p\n\0" -uint INVALID_HANDLE = 0xffffffff ~uint8 PARENT_DIR = ".." ~uint8 CURRENT_DIR = "." @@ -43,7 +42,7 @@ uint INVALID_HANDLE = 0xffffffff /; end self.path.end() - /; if (self.handle < INVALID_HANDLE && self.handle != NULL) + /; if (self.handle + 1 !== 0) _close_file(self.handle) self.handle = NULL ;/ @@ -52,17 +51,23 @@ uint INVALID_HANDLE = 0xffffffff /; open ~uint8 p = self.path.to_cstr('/') self.handle = _open_file(p) + /; if (self.handle + 1 == 0) + self.at_end = true + ;/ _delete(p) ;/ /; create ~uint8 p = self.path.to_cstr('/') self.handle = _create_file(p) + /; if (self.handle + 1 == 0) + self.at_end = true + ;/ _delete(p) ;/ /; close - /; if (self.handle !== INVALID_HANDLE && self.handle !== NULL) + /; if (self.handle + 1 !== 0) _close_file(self.handle) self.handle = NULL self.at_end = false @@ -86,4 +91,10 @@ uint INVALID_HANDLE = 0xffffffff ;/ ;/ + /; write_cstr (~uint8 str) + /; loop (self.at_end == false && str` !== 0) [str++] + self.write(str`) + ;/ + ;/ + ;/ -- cgit v1.2.3