mirror of
https://github.com/Ed94/metadesk.git
synced 2026-08-07 08:08:48 +00:00
POSIX directory listing.
This commit is contained in:
@@ -12,7 +12,7 @@ popd () {
|
|||||||
|
|
||||||
echo ~~~ Metadesk Build ~~~
|
echo ~~~ Metadesk Build ~~~
|
||||||
# TODO(mal): Review these warnings
|
# 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"
|
compile_flags="-I../source/ $accepted_clang_warnings"
|
||||||
|
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
|
|||||||
Executable → Regular
+2
-1
@@ -1,7 +1,8 @@
|
|||||||
@echo off
|
@echo off
|
||||||
|
|
||||||
echo ~~~ Metadesk Build ~~~
|
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%
|
set compile_flags=-I../source/ %accepted_clang_warnings%
|
||||||
|
|
||||||
if not exist build mkdir build
|
if not exist build mkdir build
|
||||||
|
|||||||
+51
-3
@@ -1,5 +1,53 @@
|
|||||||
|
#include <dirent.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
|
||||||
|
#define MD_IMPL_FileIterIncrement MD_POSIX_FileIterIncrement
|
||||||
|
|
||||||
static MD_b32
|
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)
|
||||||
{
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user