mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Parse directories to be packages
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
package os
|
||||
|
||||
import "core:mem"
|
||||
|
||||
write_string :: proc(fd: Handle, str: string) -> (int, Errno) {
|
||||
return write(fd, cast([]byte)str);
|
||||
}
|
||||
|
||||
write_byte :: proc(fd: Handle, b: byte) -> (int, Errno) {
|
||||
return write(fd, []byte{b});
|
||||
}
|
||||
|
||||
|
||||
read_entire_file :: proc(name: string) -> (data: []byte, success: bool) {
|
||||
fd, err := open(name, O_RDONLY, 0);
|
||||
if err != 0 {
|
||||
return nil, false;
|
||||
}
|
||||
defer close(fd);
|
||||
|
||||
length: i64;
|
||||
if length, err = file_size(fd); err != 0 {
|
||||
return nil, false;
|
||||
}
|
||||
|
||||
if length <= 0 {
|
||||
return nil, true;
|
||||
}
|
||||
|
||||
data = make([]byte, int(length));
|
||||
if data == nil {
|
||||
return nil, false;
|
||||
}
|
||||
|
||||
bytes_read, read_err := read(fd, data);
|
||||
if read_err != 0 {
|
||||
free(data);
|
||||
return nil, false;
|
||||
}
|
||||
return data[0..bytes_read], true;
|
||||
}
|
||||
|
||||
write_entire_file :: proc(name: string, data: []byte, truncate := true) -> (success: bool) {
|
||||
flags: int = O_WRONLY|O_CREATE;
|
||||
if truncate {
|
||||
flags |= O_TRUNC;
|
||||
}
|
||||
fd, err := open(name, flags, 0);
|
||||
if err != 0 {
|
||||
return false;
|
||||
}
|
||||
defer close(fd);
|
||||
|
||||
_, write_err := write(fd, data);
|
||||
return write_err == 0;
|
||||
}
|
||||
|
||||
write_ptr :: proc(fd: Handle, data: rawptr, len: int) -> (int, Errno) {
|
||||
return write(fd, mem.slice_ptr(cast(^byte)data, len));
|
||||
}
|
||||
|
||||
read_ptr :: proc(fd: Handle, data: rawptr, len: int) -> (int, Errno) {
|
||||
return read(fd, mem.slice_ptr(cast(^byte)data, len));
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
package os
|
||||
|
||||
foreign import api "system:api"
|
||||
|
||||
Handle :: distinct int;
|
||||
@@ -17,8 +19,8 @@ ERROR_PATH_NOT_WITHIN_MOUNTED_VOLUME : Errno : -14;
|
||||
ERROR_PATH_NOT_FOUND : Errno : -15;
|
||||
ERROR_FILE_EXISTS : Errno : -19;
|
||||
ERROR_FILE_NOT_FOUND : Errno : -20;
|
||||
ERROR_DRIVE_ERROR_FILE_DAMAGED : Errno : -21;
|
||||
ERROR_ACCESS_NOT_WITHIN_FILE_BOUNDS : Errno : -22;
|
||||
ERROR_DRIVE_ERROR_FILE_DAMAGED : Errno : -21;
|
||||
ERROR_ACCESS_NOT_WITHIN_FILE_BOUNDS : Errno : -22;
|
||||
ERROR_ACCESS_DENIED : Errno : -23;
|
||||
ERROR_FILE_IN_EXCLUSIVE_USE : Errno : -24;
|
||||
ERROR_FILE_CANNOT_GET_EXCLUSIVE_USE : Errno : -25;
|
||||
@@ -1,8 +1,10 @@
|
||||
package os
|
||||
|
||||
foreign import dl "system:dl"
|
||||
foreign import libc "system:c"
|
||||
|
||||
import "core:strings.odin"
|
||||
import "core:mem.odin"
|
||||
import "core:strings"
|
||||
import "core:mem"
|
||||
|
||||
Handle :: distinct i32;
|
||||
File_Time :: distinct u64;
|
||||
@@ -1,8 +1,10 @@
|
||||
package os
|
||||
|
||||
foreign import dl "system:dl"
|
||||
foreign import libc "system:c"
|
||||
|
||||
import "core:strings.odin"
|
||||
import "core:mem.odin"
|
||||
import "core:strings"
|
||||
import "core:mem"
|
||||
|
||||
Handle :: distinct i32;
|
||||
File_Time :: distinct u64;
|
||||
@@ -1,5 +1,7 @@
|
||||
import win32 "core:sys/windows.odin"
|
||||
import "core:mem.odin"
|
||||
package os
|
||||
|
||||
import "core:sys/win32"
|
||||
import "core:mem"
|
||||
|
||||
Handle :: distinct uintptr;
|
||||
File_Time :: distinct u64;
|
||||
Reference in New Issue
Block a user