using non-relative paths in file lookups
authorBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 13 May 2021 22:30:32 +0000 (17:30 -0500)
committerBrendan Hansen <brendan.f.hansen@gmail.com>
Thu, 13 May 2021 22:30:32 +0000 (17:30 -0500)
bin/onyx
include/bh.h
include/small_windows.h
src/onyx.c

index 1d0686ecadee73de6a8551e4c62e2e1f711ea6b4..c8087029211c2efacfc986b9126eb5ea30fa0239 100755 (executable)
Binary files a/bin/onyx and b/bin/onyx differ
index 4b3586da28c51ed619aba14e13c76e2f5c340c01..962d180383220f9d67fd303bfc1a8ced2b17e0fc 100644 (file)
@@ -372,6 +372,7 @@ i32 bh_file_read(bh_file* file, void* buffer, isize buff_size);
 i32 bh_file_write(bh_file* file, void* buffer, isize buff_size);
 i64 bh_file_size(bh_file* file);
 b32 bh_file_exists(char const* filename);
+char* bh_path_get_full_name(char const* filename, bh_allocator a);
 
 #define bh_file_read_contents(allocator_, x) _Generic((x), \
     bh_file*: bh_file_read_contents_bh_file, \
@@ -1548,6 +1549,27 @@ b32 bh_file_exists(char const* filename) {
     return stat(filename, &s) != -1;
 }
 
+char* bh_path_get_full_name(char const* filename, bh_allocator a) {
+#if defined(_BH_WINDOWS)
+    #error "Not supported."
+#elif defined(_BH_LINUX)
+    char* p = realpath(filename, NULL);    
+
+    // Check if the file did not exists.
+    // :Cleanup should this return NULL?
+    if (p == NULL) return (char *) filename;
+    
+    i32 len = strlen(p);
+    char* result = bh_alloc_array(a, char, len + 1);
+    memmove(result, p, len);
+    result[len] = 0;
+
+    free(p);
+
+    return result;
+#endif
+}
+
 #endif // ifndef BH_NO_FILE
 
 
index c00208b062425195986d83b40075becfd1a3fac1..22d8f7a42998c93bbfc872a2cfeb15de7b4cde47 100644 (file)
@@ -358,6 +358,8 @@ GB_DLL_IMPORT BOOL   WINAPI GetFileAttributesExW(wchar_t const *path, GET_FILEEX
 GB_DLL_IMPORT BOOL   WINAPI CopyFileW(wchar_t const *old_f, wchar_t const *new_f, BOOL fail_if_exists);
 GB_DLL_IMPORT BOOL   WINAPI MoveFileW(wchar_t const *old_f, wchar_t const *new_f);
 
+GB_DLL_IMPORT DWORD  WINAPI GetFullPathNameA(char const *lpFileName, DWORD nBufferLength, char *lpBuffer, char **lpFilePart);
+
 GB_DLL_IMPORT HMODULE WINAPI LoadLibraryA  (char const *filename);
 GB_DLL_IMPORT BOOL    WINAPI FreeLibrary   (HMODULE module);
 GB_DLL_IMPORT FARPROC WINAPI GetProcAddress(HMODULE module, char const *name);
index ce3c4b06de8f97830ab1ba7c29ecd3334ac76c4c..ec2e54d5774ed293d7c48cc172b25d1993589413 100644 (file)
@@ -237,7 +237,7 @@ static char* lookup_included_file(char* filename, char* relative_to) {
         else
             bh_snprintf(path, 256, "%s%s", *folder, fn);
 
-        if (bh_file_exists(path)) return path;
+        if (bh_file_exists(path)) return bh_path_get_full_name(path, global_scratch_allocator);
     }
 
     return fn;