mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-07 16:18:52 +00:00
Use long-form names and alias with short-form UNIX-like names
This commit is contained in:
+21
-15
@@ -156,41 +156,46 @@ read_link :: proc(name: string, allocator: runtime.Allocator) -> (string, Error)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
chdir :: proc(name: string) -> Error {
|
chdir :: change_directory
|
||||||
|
change_directory :: proc(name: string) -> Error {
|
||||||
return _chdir(name)
|
return _chdir(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
chmod :: proc(name: string, mode: File_Mode) -> Error {
|
chmod :: change_mode
|
||||||
|
change_mode :: proc(name: string, mode: File_Mode) -> Error {
|
||||||
return _chmod(name, mode)
|
return _chmod(name, mode)
|
||||||
}
|
}
|
||||||
|
chown :: change_owner
|
||||||
chown :: proc(name: string, uid, gid: int) -> Error {
|
change_owner :: proc(name: string, uid, gid: int) -> Error {
|
||||||
return _chown(name, uid, gid)
|
return _chown(name, uid, gid)
|
||||||
}
|
}
|
||||||
|
|
||||||
fchdir :: proc(f: ^File) -> Error {
|
fchdir :: fchange_directory
|
||||||
|
fchange_directory :: proc(f: ^File) -> Error {
|
||||||
return _fchdir(f)
|
return _fchdir(f)
|
||||||
}
|
}
|
||||||
|
fchmod :: fchange_mode
|
||||||
fchmod :: proc(f: ^File, mode: File_Mode) -> Error {
|
fchange_mode :: proc(f: ^File, mode: File_Mode) -> Error {
|
||||||
return _fchmod(f, mode)
|
return _fchmod(f, mode)
|
||||||
}
|
}
|
||||||
|
|
||||||
fchown :: proc(f: ^File, uid, gid: int) -> Error {
|
fchown :: fchange_owner
|
||||||
|
fchange_owner :: proc(f: ^File, uid, gid: int) -> Error {
|
||||||
return _fchown(f, uid, gid)
|
return _fchown(f, uid, gid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
lchown :: change_owner_do_not_follow_links
|
||||||
lchown :: proc(name: string, uid, gid: int) -> Error {
|
change_owner_do_not_follow_links :: proc(name: string, uid, gid: int) -> Error {
|
||||||
return _lchown(name, uid, gid)
|
return _lchown(name, uid, gid)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chtimes :: change_times
|
||||||
chtimes :: proc(name: string, atime, mtime: time.Time) -> Error {
|
change_times :: proc(name: string, atime, mtime: time.Time) -> Error {
|
||||||
return _chtimes(name, atime, mtime)
|
return _chtimes(name, atime, mtime)
|
||||||
}
|
}
|
||||||
fchtimes :: proc(f: ^File, atime, mtime: time.Time) -> Error {
|
fchtimes :: fchange_times
|
||||||
|
fchange_times :: proc(f: ^File, atime, mtime: time.Time) -> Error {
|
||||||
return _fchtimes(f, atime, mtime)
|
return _fchtimes(f, atime, mtime)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -202,7 +207,8 @@ is_file :: proc(path: string) -> bool {
|
|||||||
return _is_file(path)
|
return _is_file(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
is_dir :: proc(path: string) -> bool {
|
is_dir :: is_directory
|
||||||
|
is_directory :: proc(path: string) -> bool {
|
||||||
return _is_dir(path)
|
return _is_dir(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,7 +219,7 @@ copy_file :: proc(dst_path, src_path: string) -> Error {
|
|||||||
|
|
||||||
info := fstat(src, _file_allocator()) or_return
|
info := fstat(src, _file_allocator()) or_return
|
||||||
defer file_info_delete(info, _file_allocator())
|
defer file_info_delete(info, _file_allocator())
|
||||||
if info.is_dir {
|
if info.is_directory {
|
||||||
return .Invalid_File
|
return .Invalid_File
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,14 +74,21 @@ read_ptr :: proc(f: ^File, data: rawptr, len: int) -> (n: int, err: Error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
read_entire_file :: proc{
|
||||||
|
read_entire_file_from_path,
|
||||||
|
read_entire_file_from_file,
|
||||||
|
}
|
||||||
|
|
||||||
read_entire_file :: proc(name: string, allocator: runtime.Allocator) -> (data: []byte, err: Error) {
|
read_entire_file_from_path :: proc(name: string, allocator: runtime.Allocator) -> (data: []byte, err: Error) {
|
||||||
f, ferr := open(name)
|
f, ferr := open(name)
|
||||||
if ferr != nil {
|
if ferr != nil {
|
||||||
return nil, ferr
|
return nil, ferr
|
||||||
}
|
}
|
||||||
defer close(f)
|
defer close(f)
|
||||||
|
return read_entire_file_from_file(f, allocator)
|
||||||
|
}
|
||||||
|
|
||||||
|
read_entire_file_from_file :: proc(f: ^File, allocator: runtime.Allocator) -> (data: []byte, err: Error) {
|
||||||
size: int
|
size: int
|
||||||
if size64, err := file_size(f); err == nil {
|
if size64, err := file_size(f); err == nil {
|
||||||
if i64(int(size64)) != size64 {
|
if i64(int(size64)) != size64 {
|
||||||
|
|||||||
@@ -200,7 +200,7 @@ _heap_allocator_proc :: proc(allocator_data: rawptr, mode: mem.Allocator_Mode,
|
|||||||
case .Free_All:
|
case .Free_All:
|
||||||
return nil, .Mode_Not_Implemented
|
return nil, .Mode_Not_Implemented
|
||||||
|
|
||||||
case .Resize:
|
case .Resize, .Resize_Non_Zeroed:
|
||||||
if old_memory == nil {
|
if old_memory == nil {
|
||||||
return aligned_alloc(size, alignment)
|
return aligned_alloc(size, alignment)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,11 +9,13 @@ is_path_separator :: proc(c: byte) -> bool {
|
|||||||
return _is_path_separator(c)
|
return _is_path_separator(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
mkdir :: proc(name: string, perm: File_Mode) -> Error {
|
mkdir :: make_directory
|
||||||
|
make_directory :: proc(name: string, perm: File_Mode) -> Error {
|
||||||
return _mkdir(name, perm)
|
return _mkdir(name, perm)
|
||||||
}
|
}
|
||||||
|
|
||||||
mkdir_all :: proc(path: string, perm: File_Mode) -> Error {
|
mkdir_all :: make_directory_all
|
||||||
|
make_directory_all :: proc(path: string, perm: File_Mode) -> Error {
|
||||||
return _mkdir_all(path, perm)
|
return _mkdir_all(path, perm)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -22,10 +24,12 @@ remove_all :: proc(path: string) -> Error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
getwd :: get_working_directory
|
||||||
getwd :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
get_working_directory :: proc(allocator: runtime.Allocator) -> (dir: string, err: Error) {
|
||||||
return _getwd(allocator)
|
return _getwd(allocator)
|
||||||
}
|
}
|
||||||
setwd :: proc(dir: string) -> (err: Error) {
|
|
||||||
|
setwd :: set_working_directory
|
||||||
|
set_working_directory :: proc(dir: string) -> (err: Error) {
|
||||||
return _setwd(dir)
|
return _setwd(dir)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ _mkdir_all :: proc(path: string, perm: File_Mode) -> Error {
|
|||||||
|
|
||||||
dir, err := stat(path, _temp_allocator())
|
dir, err := stat(path, _temp_allocator())
|
||||||
if err == nil {
|
if err == nil {
|
||||||
if dir.is_dir {
|
if dir.is_directory {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return .Exist
|
return .Exist
|
||||||
@@ -60,7 +60,7 @@ _mkdir_all :: proc(path: string, perm: File_Mode) -> Error {
|
|||||||
err = mkdir(path, perm)
|
err = mkdir(path, perm)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
dir1, err1 := lstat(path, _temp_allocator())
|
dir1, err1 := lstat(path, _temp_allocator())
|
||||||
if err1 == nil && dir1.is_dir {
|
if err1 == nil && dir1.is_directory {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -4,11 +4,11 @@ import "core:time"
|
|||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
|
|
||||||
File_Info :: struct {
|
File_Info :: struct {
|
||||||
fullpath: string,
|
fullpath: string,
|
||||||
name: string,
|
name: string,
|
||||||
size: i64,
|
size: i64,
|
||||||
mode: File_Mode,
|
mode: File_Mode,
|
||||||
is_dir: bool,
|
is_directory: bool,
|
||||||
creation_time: time.Time,
|
creation_time: time.Time,
|
||||||
modification_time: time.Time,
|
modification_time: time.Time,
|
||||||
access_time: time.Time,
|
access_time: time.Time,
|
||||||
@@ -33,7 +33,8 @@ stat :: proc(name: string, allocator: runtime.Allocator) -> (File_Info, Error) {
|
|||||||
return _stat(name, allocator)
|
return _stat(name, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
lstat :: proc(name: string, allocator: runtime.Allocator) -> (File_Info, Error) {
|
lstat :: stat_do_not_follow_links
|
||||||
|
stat_do_not_follow_links :: proc(name: string, allocator: runtime.Allocator) -> (File_Info, Error) {
|
||||||
return _lstat(name, allocator)
|
return _lstat(name, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ _fstat_internal :: proc(fd: int, allocator: runtime.Allocator) -> (File_Info, Er
|
|||||||
name = "",
|
name = "",
|
||||||
size = s.size,
|
size = s.size,
|
||||||
mode = 0,
|
mode = 0,
|
||||||
is_dir = S_ISDIR(s.mode),
|
is_directory = S_ISDIR(s.mode),
|
||||||
modification_time = time.Time {s.modified.seconds},
|
modification_time = time.Time {s.modified.seconds},
|
||||||
access_time = time.Time {s.last_access.seconds},
|
access_time = time.Time {s.last_access.seconds},
|
||||||
creation_time = time.Time{0}, // regular stat does not provide this
|
creation_time = time.Time{0}, // regular stat does not provide this
|
||||||
|
|||||||
@@ -228,7 +228,7 @@ _file_info_from_win32_file_attribute_data :: proc(d: ^win32.WIN32_FILE_ATTRIBUTE
|
|||||||
fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow)
|
fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow)
|
||||||
|
|
||||||
fi.mode |= _file_mode_from_file_attributes(d.dwFileAttributes, nil, 0)
|
fi.mode |= _file_mode_from_file_attributes(d.dwFileAttributes, nil, 0)
|
||||||
fi.is_dir = fi.mode & File_Mode_Dir != 0
|
fi.is_directory = fi.mode & File_Mode_Dir != 0
|
||||||
|
|
||||||
fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime))
|
fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime))
|
||||||
fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime))
|
fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime))
|
||||||
@@ -245,7 +245,7 @@ _file_info_from_win32_find_data :: proc(d: ^win32.WIN32_FIND_DATAW, name: string
|
|||||||
fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow)
|
fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow)
|
||||||
|
|
||||||
fi.mode |= _file_mode_from_file_attributes(d.dwFileAttributes, nil, 0)
|
fi.mode |= _file_mode_from_file_attributes(d.dwFileAttributes, nil, 0)
|
||||||
fi.is_dir = fi.mode & File_Mode_Dir != 0
|
fi.is_directory = fi.mode & File_Mode_Dir != 0
|
||||||
|
|
||||||
fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime))
|
fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime))
|
||||||
fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime))
|
fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime))
|
||||||
@@ -282,7 +282,7 @@ _file_info_from_get_file_information_by_handle :: proc(path: string, h: win32.HA
|
|||||||
fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow)
|
fi.size = i64(d.nFileSizeHigh)<<32 + i64(d.nFileSizeLow)
|
||||||
|
|
||||||
fi.mode |= _file_mode_from_file_attributes(ti.FileAttributes, h, ti.ReparseTag)
|
fi.mode |= _file_mode_from_file_attributes(ti.FileAttributes, h, ti.ReparseTag)
|
||||||
fi.is_dir = fi.mode & File_Mode_Dir != 0
|
fi.is_directory = fi.mode & File_Mode_Dir != 0
|
||||||
|
|
||||||
fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime))
|
fi.creation_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftCreationTime))
|
||||||
fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime))
|
fi.modification_time = time.unix(0, win32.FILETIME_as_unix_nanoseconds(d.ftLastWriteTime))
|
||||||
|
|||||||
@@ -2,14 +2,16 @@ package os2
|
|||||||
|
|
||||||
import "base:runtime"
|
import "base:runtime"
|
||||||
|
|
||||||
create_temp :: proc(dir, pattern: string) -> (^File, Error) {
|
create_temp_file :: proc(dir, pattern: string) -> (^File, Error) {
|
||||||
return _create_temp(dir, pattern)
|
return _create_temp(dir, pattern)
|
||||||
}
|
}
|
||||||
|
|
||||||
mkdir_temp :: proc(dir, pattern: string, allocator: runtime.Allocator) -> (string, Error) {
|
mkdir_temp :: make_directory_temp
|
||||||
|
make_directory_temp :: proc(dir, pattern: string, allocator: runtime.Allocator) -> (string, Error) {
|
||||||
return _mkdir_temp(dir, pattern, allocator)
|
return _mkdir_temp(dir, pattern, allocator)
|
||||||
}
|
}
|
||||||
|
|
||||||
temp_dir :: proc(allocator: runtime.Allocator) -> (string, Error) {
|
temp_dir :: temp_directory
|
||||||
|
temp_directory :: proc(allocator: runtime.Allocator) -> (string, Error) {
|
||||||
return _temp_dir(allocator)
|
return _temp_dir(allocator)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user