Browse Source

Merge branch 'master' of https://github.com/odin-lang/Odin

gingerBill 4 years ago
parent
commit
0061e63db0
2 changed files with 16 additions and 3 deletions
  1. 2 2
      core/path/filepath/path.odin
  2. 14 1
      src/common.cpp

+ 2 - 2
core/path/filepath/path.odin

@@ -241,7 +241,7 @@ rel :: proc(base_path, target_path: string, allocator := context.allocator) -> (
 		for ti < tl && target[ti] != SEPARATOR {
 		for ti < tl && target[ti] != SEPARATOR {
 			ti += 1;
 			ti += 1;
 		}
 		}
-		if !strings.equal_fold(target[t0:ti], base[t0:ti]) {
+		if !strings.equal_fold(target[t0:ti], base[b0:bi]) {
 			break;
 			break;
 		}
 		}
 		if bi < bl {
 		if bi < bl {
@@ -284,7 +284,7 @@ rel :: proc(base_path, target_path: string, allocator := context.allocator) -> (
 dir :: proc(path: string, allocator := context.allocator) -> string {
 dir :: proc(path: string, allocator := context.allocator) -> string {
 	vol := volume_name(path);
 	vol := volume_name(path);
 	i := len(path) - 1;
 	i := len(path) - 1;
-	for i >= len(vol) && is_separator(path[i]) {
+	for i >= len(vol) && !is_separator(path[i]) {
 		i -= 1;
 		i -= 1;
 	}
 	}
 	dir := clean(path[len(vol) : i+1], allocator);
 	dir := clean(path[len(vol) : i+1], allocator);

+ 14 - 1
src/common.cpp

@@ -968,7 +968,20 @@ ReadDirectoryError read_directory(String path, Array<FileInfo> *fi) {
 
 
 	DIR *dir = opendir(c_path);
 	DIR *dir = opendir(c_path);
 	if (!dir) {
 	if (!dir) {
-		return ReadDirectory_NotDir;
+		switch (errno) {
+		case ENOENT:
+			return ReadDirectory_NotExists;
+		case EACCES:
+			return ReadDirectory_Permission;
+		case ENOTDIR:
+			return ReadDirectory_NotDir;
+		default:
+			// ENOMEM: out of memory
+			// EMFILE: per-process limit on open fds reached
+			// ENFILE: system-wide limit on total open files reached
+			return ReadDirectory_Unknown;
+		}
+		GB_PANIC("unreachable");
 	}
 	}
 
 
 	array_init(fi, a, 0, 100);
 	array_init(fi, a, 0, 100);