123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- package os2
- import "core:io"
- import "core:time"
- Handle :: distinct uintptr;
- Seek_From :: enum {
- Start = 0, // seek relative to the origin of the file
- Current = 1, // seek relative to the current offset
- End = 2, // seek relative to the end
- }
- File_Mode :: distinct u32;
- File_Mode_Dir :: File_Mode(1<<16);
- File_Mode_Named_Pipe :: File_Mode(1<<17);
- File_Mode_Device :: File_Mode(1<<18);
- File_Mode_Char_Device :: File_Mode(1<<19);
- File_Mode_Sym_Link :: File_Mode(1<<20);
- O_RDONLY :: int( 0);
- O_WRONLY :: int( 1);
- O_RDWR :: int( 2);
- O_APPEND :: int( 4);
- O_CREATE :: int( 8);
- O_EXCL :: int(16);
- O_SYNC :: int(32);
- O_TRUNC :: int(64);
- stdin: Handle = 0; // OS-Specific
- stdout: Handle = 1; // OS-Specific
- stderr: Handle = 2; // OS-Specific
- create :: proc(name: string) -> (Handle, Error) {
- return _create(name);
- }
- open :: proc(name: string) -> (Handle, Error) {
- return _open(name);
- }
- open_file :: proc(name: string, flag: int, perm: File_Mode) -> (Handle, Error) {
- return _open_file(name, flag, perm);
- }
- close :: proc(fd: Handle) -> Error {
- return _close(fd);
- }
- name :: proc(fd: Handle, allocator := context.allocator) -> string {
- return _name(fd);
- }
- seek :: proc(fd: Handle, offset: i64, whence: Seek_From) -> (ret: i64, err: Error) {
- return _seek(fd, offset, whence);
- }
- read :: proc(fd: Handle, p: []byte) -> (n: int, err: Error) {
- return _read(fd, p);
- }
- read_at :: proc(fd: Handle, p: []byte, offset: i64) -> (n: int, err: Error) {
- return _read_at(fd, p, offset);
- }
- read_from :: proc(fd: Handle, r: io.Reader) -> (n: i64, err: Error) {
- return _read_from(fd, r);
- }
- write :: proc(fd: Handle, p: []byte) -> (n: int, err: Error) {
- return _write(fd, p);
- }
- write_at :: proc(fd: Handle, p: []byte, offset: i64) -> (n: int, err: Error) {
- return _write_at(fd, p, offset);
- }
- write_to :: proc(fd: Handle, w: io.Writer) -> (n: i64, err: Error) {
- return _write_to(fd, w);
- }
- file_size :: proc(fd: Handle) -> (n: i64, err: Error) {
- return _file_size(fd);
- }
- sync :: proc(fd: Handle) -> Error {
- return _sync(fd);
- }
- flush :: proc(fd: Handle) -> Error {
- return _flush(fd);
- }
- truncate :: proc(fd: Handle, size: i64) -> Maybe(Path_Error) {
- return _truncate(fd, size);
- }
- remove :: proc(name: string) -> Maybe(Path_Error) {
- return _remove(name);
- }
- rename :: proc(old_path, new_path: string) -> Maybe(Path_Error) {
- return _rename(old_path, new_path);
- }
- link :: proc(old_name, new_name: string) -> Maybe(Link_Error) {
- return _link(old_name, new_name);
- }
- symlink :: proc(old_name, new_name: string) -> Maybe(Link_Error) {
- return _symlink(old_name, new_name);
- }
- read_link :: proc(name: string) -> (string, Maybe(Path_Error)) {
- return _read_link(name);
- }
- chdir :: proc(fd: Handle) -> Error {
- return _chdir(fd);
- }
- chmod :: proc(fd: Handle, mode: File_Mode) -> Error {
- return _chmod(fd, mode);
- }
- chown :: proc(fd: Handle, uid, gid: int) -> Error {
- return _chown(fd, uid, gid);
- }
- lchown :: proc(name: string, uid, gid: int) -> Error {
- return _lchown(name, uid, gid);
- }
- chtimes :: proc(name: string, atime, mtime: time.Time) -> Maybe(Path_Error) {
- return _chtimes(name, atime, mtime);
- }
- exists :: proc(path: string) -> bool {
- return _exists(path);
- }
- is_file :: proc(path: string) -> bool {
- return _is_file(path);
- }
- is_dir :: proc(path: string) -> bool {
- return _is_dir(path);
- }
|