mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 23:58:50 +00:00
Prefix proc syntax
This commit is contained in:
+45
-45
@@ -107,13 +107,13 @@ const S_ISUID = 0004000; // Set user id on execution
|
||||
const S_ISGID = 0002000; // Set group id on execution
|
||||
const S_ISVTX = 0001000; // Directory restrcted delete
|
||||
|
||||
const S_ISLNK = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFLNK; }
|
||||
const S_ISREG = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFREG; }
|
||||
const S_ISDIR = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFDIR; }
|
||||
const S_ISCHR = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFCHR; }
|
||||
const S_ISBLK = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFBLK; }
|
||||
const S_ISFIFO = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFIFO; }
|
||||
const S_ISSOCK = proc(m: u32) -> bool #inline {return ((m) & S_IFMT) == S_IFSOCK;}
|
||||
proc S_ISLNK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFLNK; }
|
||||
proc S_ISREG (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFREG; }
|
||||
proc S_ISDIR (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFDIR; }
|
||||
proc S_ISCHR (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFCHR; }
|
||||
proc S_ISBLK (m: u32) -> bool #inline {return (m & S_IFMT) == S_IFBLK; }
|
||||
proc S_ISFIFO(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFIFO; }
|
||||
proc S_ISSOCK(m: u32) -> bool #inline {return (m & S_IFMT) == S_IFSOCK;}
|
||||
|
||||
const R_OK = 4; // Test for read permission
|
||||
const W_OK = 2; // Test for write permission
|
||||
@@ -123,30 +123,30 @@ const F_OK = 0; // Test for file existance
|
||||
#foreign_system_library dl "dl";
|
||||
#foreign_system_library libc "c";
|
||||
|
||||
const unix_open = proc(path: ^u8, mode: int) -> Handle #foreign libc "open";
|
||||
const unix_close = proc(handle: Handle) #foreign libc "close";
|
||||
const unix_read = proc(handle: Handle, buffer: rawptr, count: int) -> AddressSize #foreign libc "read";
|
||||
const unix_write = proc(handle: Handle, buffer: rawptr, count: int) -> AddressSize #foreign libc "write";
|
||||
const unix_lseek = proc(fs: Handle, offset: AddressSize, whence: int) -> AddressSize #foreign libc "lseek";
|
||||
const unix_gettid = proc() -> u64 #foreign libc "gettid";
|
||||
const unix_stat = proc(path: ^u8, stat: ^Stat) -> int #foreign libc "stat";
|
||||
const unix_access = proc(path: ^u8, mask: int) -> int #foreign libc "access";
|
||||
proc unix_open (path: ^u8, mode: int) -> Handle #foreign libc "open";
|
||||
proc unix_close (handle: Handle) #foreign libc "close";
|
||||
proc unix_read (handle: Handle, buffer: rawptr, count: int) -> AddressSize #foreign libc "read";
|
||||
proc unix_write (handle: Handle, buffer: rawptr, count: int) -> AddressSize #foreign libc "write";
|
||||
proc unix_lseek (fs: Handle, offset: AddressSize, whence: int) -> AddressSize #foreign libc "lseek";
|
||||
proc unix_gettid() -> u64 #foreign libc "gettid";
|
||||
proc unix_stat (path: ^u8, stat: ^Stat) -> int #foreign libc "stat";
|
||||
proc unix_access(path: ^u8, mask: int) -> int #foreign libc "access";
|
||||
|
||||
const unix_malloc = proc(size: int) -> rawptr #foreign libc "malloc";
|
||||
const unix_free = proc(ptr: rawptr) #foreign libc "free";
|
||||
const unix_realloc = proc(ptr: rawptr, size: int) -> rawptr #foreign libc "realloc";
|
||||
const unix_getenv = proc(^u8) -> ^u8 #foreign libc "getenv";
|
||||
proc unix_malloc (size: int) -> rawptr #foreign libc "malloc";
|
||||
proc unix_free (ptr: rawptr) #foreign libc "free";
|
||||
proc unix_realloc(ptr: rawptr, size: int) -> rawptr #foreign libc "realloc";
|
||||
proc unix_getenv (^u8) -> ^u8 #foreign libc "getenv";
|
||||
|
||||
const unix_exit = proc(status: int) #foreign libc "exit";
|
||||
proc unix_exit(status: int) #foreign libc "exit";
|
||||
|
||||
const unix_dlopen = proc(filename: ^u8, flags: int) -> rawptr #foreign dl "dlopen";
|
||||
const unix_dlsym = proc(handle: rawptr, symbol: ^u8) -> (proc() #cc_c) #foreign dl "dlsym";
|
||||
const unix_dlclose = proc(handle: rawptr) -> int #foreign dl "dlclose";
|
||||
const unix_dlerror = proc() -> ^u8 #foreign dl "dlerror";
|
||||
proc unix_dlopen (filename: ^u8, flags: int) -> rawptr #foreign dl "dlopen";
|
||||
proc unix_dlsym (handle: rawptr, symbol: ^u8) -> (proc() #cc_c) #foreign dl "dlsym";
|
||||
proc unix_dlclose(handle: rawptr) -> int #foreign dl "dlclose";
|
||||
proc unix_dlerror() -> ^u8 #foreign dl "dlerror";
|
||||
|
||||
|
||||
// TODO(zangent): Change this to just `open` when Bill fixes overloading.
|
||||
const open_simple = proc(path: string, mode: int) -> (Handle, Errno) {
|
||||
proc open_simple(path: string, mode: int) -> (Handle, Errno) {
|
||||
|
||||
var cstr = strings.new_c_string(path);
|
||||
var handle = unix_open(cstr, mode);
|
||||
@@ -158,15 +158,15 @@ const open_simple = proc(path: string, mode: int) -> (Handle, Errno) {
|
||||
}
|
||||
|
||||
// NOTE(zangent): This is here for compatability reasons. Should this be here?
|
||||
const open = proc(path: string, mode: int, perm: u32) -> (Handle, Errno) {
|
||||
proc open(path: string, mode: int, perm: u32) -> (Handle, Errno) {
|
||||
return open_simple(path, mode);
|
||||
}
|
||||
|
||||
const close = proc(fd: Handle) {
|
||||
proc close(fd: Handle) {
|
||||
unix_close(fd);
|
||||
}
|
||||
|
||||
const write = proc(fd: Handle, data: []u8) -> (AddressSize, Errno) {
|
||||
proc write(fd: Handle, data: []u8) -> (AddressSize, Errno) {
|
||||
assert(fd != -1);
|
||||
|
||||
var bytes_written = unix_write(fd, &data[0], len(data));
|
||||
@@ -176,7 +176,7 @@ const write = proc(fd: Handle, data: []u8) -> (AddressSize, Errno) {
|
||||
return bytes_written, 0;
|
||||
}
|
||||
|
||||
const read = proc(fd: Handle, data: []u8) -> (AddressSize, Errno) {
|
||||
proc read(fd: Handle, data: []u8) -> (AddressSize, Errno) {
|
||||
assert(fd != -1);
|
||||
|
||||
var bytes_read = unix_read(fd, &data[0], len(data));
|
||||
@@ -186,7 +186,7 @@ const read = proc(fd: Handle, data: []u8) -> (AddressSize, Errno) {
|
||||
return bytes_read, 0;
|
||||
}
|
||||
|
||||
const seek = proc(fd: Handle, offset: AddressSize, whence: int) -> (AddressSize, Errno) {
|
||||
proc seek(fd: Handle, offset: AddressSize, whence: int) -> (AddressSize, Errno) {
|
||||
assert(fd != -1);
|
||||
|
||||
var final_offset = unix_lseek(fd, offset, whence);
|
||||
@@ -196,7 +196,7 @@ const seek = proc(fd: Handle, offset: AddressSize, whence: int) -> (AddressSize,
|
||||
return final_offset, 0;
|
||||
}
|
||||
|
||||
const file_size = proc(fd: Handle) -> (i64, Errno) {
|
||||
proc file_size(fd: Handle) -> (i64, Errno) {
|
||||
var prev, _ = seek(fd, 0, SEEK_CUR);
|
||||
var size, err = seek(fd, 0, SEEK_END);
|
||||
seek(fd, prev, SEEK_SET);
|
||||
@@ -211,11 +211,11 @@ var stdout: Handle = 1; // get_std_handle(win32.STD_OUTPUT_HANDLE);
|
||||
var stderr: Handle = 2; // get_std_handle(win32.STD_ERROR_HANDLE);
|
||||
|
||||
/* TODO(zangent): Implement these!
|
||||
const last_write_time = proc(fd: Handle) -> FileTime {}
|
||||
const last_write_time_by_name = proc(name: string) -> FileTime {}
|
||||
proc last_write_time(fd: Handle) -> FileTime {}
|
||||
proc last_write_time_by_name(name: string) -> FileTime {}
|
||||
*/
|
||||
|
||||
const stat = proc(path: string) -> (Stat, bool) #inline {
|
||||
proc stat(path: string) -> (Stat, bool) #inline {
|
||||
var s: Stat;
|
||||
var cstr = strings.new_c_string(path);
|
||||
defer free(cstr);
|
||||
@@ -223,24 +223,24 @@ const stat = proc(path: string) -> (Stat, bool) #inline {
|
||||
return s, ret_int==0;
|
||||
}
|
||||
|
||||
const access = proc(path: string, mask: int) -> bool #inline {
|
||||
proc access(path: string, mask: int) -> bool #inline {
|
||||
var cstr = strings.new_c_string(path);
|
||||
defer free(cstr);
|
||||
return unix_access(cstr, mask) == 0;
|
||||
}
|
||||
|
||||
const heap_alloc = proc(size: int) -> rawptr #inline {
|
||||
proc heap_alloc(size: int) -> rawptr #inline {
|
||||
assert(size > 0);
|
||||
return unix_malloc(size);
|
||||
}
|
||||
const heap_resize = proc(ptr: rawptr, new_size: int) -> rawptr #inline {
|
||||
proc heap_resize(ptr: rawptr, new_size: int) -> rawptr #inline {
|
||||
return unix_realloc(ptr, new_size);
|
||||
}
|
||||
const heap_free = proc(ptr: rawptr) #inline {
|
||||
proc heap_free(ptr: rawptr) #inline {
|
||||
unix_free(ptr);
|
||||
}
|
||||
|
||||
const getenv = proc(name: string) -> (string, bool) {
|
||||
proc getenv(name: string) -> (string, bool) {
|
||||
var path_str = strings.new_c_string(name);
|
||||
var cstr: ^u8 = unix_getenv(path_str);
|
||||
free(path_str);
|
||||
@@ -250,33 +250,33 @@ const getenv = proc(name: string) -> (string, bool) {
|
||||
return strings.to_odin_string(cstr), true;
|
||||
}
|
||||
|
||||
const exit = proc(code: int) #inline {
|
||||
proc exit(code: int) #inline {
|
||||
unix_exit(code);
|
||||
}
|
||||
|
||||
|
||||
const current_thread_id = proc() -> int {
|
||||
proc current_thread_id() -> int {
|
||||
// return cast(int) unix_gettid();
|
||||
return 0;
|
||||
}
|
||||
|
||||
const dlopen = proc(filename: string, flags: int) -> rawptr #inline {
|
||||
proc dlopen(filename: string, flags: int) -> rawptr #inline {
|
||||
var cstr = strings.new_c_string(filename);
|
||||
var handle = unix_dlopen(cstr, flags);
|
||||
free(cstr);
|
||||
return handle;
|
||||
}
|
||||
const dlsym = proc(handle: rawptr, symbol: string) -> (proc() #cc_c) #inline {
|
||||
proc dlsym(handle: rawptr, symbol: string) -> (proc() #cc_c) #inline {
|
||||
assert(handle != nil);
|
||||
var cstr = strings.new_c_string(symbol);
|
||||
var proc_handle = unix_dlsym(handle, cstr);
|
||||
free(cstr);
|
||||
return proc_handle;
|
||||
}
|
||||
const dlclose = proc(handle: rawptr) -> bool #inline {
|
||||
proc dlclose(handle: rawptr) -> bool #inline {
|
||||
assert(handle != nil);
|
||||
return unix_dlclose(handle) == 0;
|
||||
}
|
||||
const dlerror = proc() -> string {
|
||||
proc dlerror() -> string {
|
||||
return strings.to_odin_string(unix_dlerror());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user