diff --git a/build.sh b/build.sh index c2adb2c..464bc20 100755 --- a/build.sh +++ b/build.sh @@ -12,7 +12,7 @@ popd () { echo ~~~ Metadesk Build ~~~ # TODO(mal): Review these warnings -accepted_clang_warnings="-Wno-return-type -Wno-pointer-sign -Wno-writable-strings -Wno-unknown-warning-option" +accepted_clang_warnings="-Wno-deprecated-declarations -Wno-pointer-sign -Wno-writable-strings -Wno-unknown-warning-option" compile_flags="-I../source/ $accepted_clang_warnings" mkdir -p build diff --git a/build_with_clang.bat b/build_with_clang.bat old mode 100755 new mode 100644 index e292eb9..96090c9 --- a/build_with_clang.bat +++ b/build_with_clang.bat @@ -1,7 +1,8 @@ @echo off echo ~~~ Metadesk Build ~~~ -set accepted_clang_warnings=-Wno-return-type -Wno-deprecated-declarations -Wno-pointer-sign -Wno-writable-strings -Wno-unknown-warning-option +rem TODO(mal): Review these warnings +set accepted_clang_warnings=-Wno-deprecated-declarations -Wno-pointer-sign -Wno-writable-strings -Wno-unknown-warning-option set compile_flags=-I../source/ %accepted_clang_warnings% if not exist build mkdir build diff --git a/source/md_posix.c b/source/md_posix.c index 52b3483..86ebc0c 100644 --- a/source/md_posix.c +++ b/source/md_posix.c @@ -1,5 +1,53 @@ +#include +#include + +#define MD_IMPL_FileIterIncrement MD_POSIX_FileIterIncrement + static MD_b32 -_MD_OS_IMPL_FileIter_Increment(MD_FileIter *it, MD_String8 path, MD_FileInfo *out_info) +MD_POSIX_FileIterIncrement(MD_FileIter *it, MD_String8 path, MD_FileInfo *out_info) { - -} \ No newline at end of file + MD_b32 result = 0; + + DIR *dir = (DIR *)(it->state); + if(dir == 0) + { + dir = opendir((char*)path.str); + } + + struct dirent *dir_entry = 0; + if(dir && (dir_entry = readdir(dir))) + { + out_info->filename = MD_PushStringF("%s", dir_entry->d_name); + out_info->flags = 0; + + if(path.size > 1 && path.str[path.size-1] == '/') + { + path.size -= 1; + } + MD_String8 cfile_path = MD_PushStringF("%.*s/%s", MD_StringExpand(path), dir_entry->d_name); + + // NOTE(mal): On Linux, fstatat(2) would save us from doing path manipulation and avoid some race + // conditions but we would need to make space for an extra directory file descriptor + // inside MD_FileIter struct. We would also stop being POSIX-compliant. + struct stat st; + if(stat((char *)cfile_path.str, &st) == 0) + { + if((st.st_mode & S_IFMT) == S_IFDIR) + { + out_info->flags |= MD_FileFlag_Directory; + } + out_info->file_size = st.st_size; + } + result = 1; + } + else + { + closedir(dir); + dir = 0; + result = 0; + } + + it->state = *(MD_u64 *)(&dir); + + return result; +}