* Add some procedures to path_unix to mirror the path_windows API

* Add files stat_linux and dir_linux to mirror the stat/dir_windows API
* Add helper functions to os_linux that are used by the above
This commit is contained in:
Luka Aleksić
2021-01-21 20:20:38 +01:00
parent 00ebc877a1
commit 92e23ec397
5 changed files with 352 additions and 13 deletions
+10 -8
View File
@@ -218,6 +218,7 @@ get_escape :: proc(chunk: string) -> (r: rune, next_chunk: string, err: Match_Er
//
// glob ignores file system errors
//
glob :: proc(pattern: string, allocator := context.allocator) -> (matches: []string, err: Match_Error) {
if !has_meta(pattern) {
// TODO(bill): os.lstat on here to check for error
@@ -272,14 +273,15 @@ _glob :: proc(dir, pattern: string, matches: ^[dynamic]string) -> (m: [dynamic]s
}
defer os.close(d);
file_info, ferr := os.fstat(d);
if ferr != 0 {
os.file_info_delete(file_info);
return;
}
if !file_info.is_dir {
os.file_info_delete(file_info);
return;
{
file_info, ferr := os.fstat(d);
defer os.file_info_delete(file_info);
if ferr != 0 {
return;
}
if !file_info.is_dir {
return;
}
}
+20
View File
@@ -1,6 +1,26 @@
//+build linux, darwin, freebsd
package filepath
import "core:strings"
import "core:os"
SEPARATOR :: '/';
SEPARATOR_STRING :: `/`;
LIST_SEPARATOR :: ':';
abs :: proc(path: string, allocator := context.allocator) -> (string, bool) {
full_path, err := os.absolute_path_from_relative(path);
if err != os.ERROR_NONE {
return "", false;
}
return full_path, true;
}
join :: proc(elems: ..string, allocator := context.allocator) -> string {
s := strings.join(elems, SEPARATOR_STRING);
return s;
}
is_abs :: proc(path: string) -> bool {
return (path[0] == '/');
}