Finished implmenting system_get_file_list.
This commit is contained in:
parent
ea29a6e13e
commit
9c3a2d9550
|
@ -38,9 +38,6 @@
|
||||||
|
|
||||||
#include "mac_objective_c_to_cpp_links.h"
|
#include "mac_objective_c_to_cpp_links.h"
|
||||||
|
|
||||||
#include <errno.h>
|
|
||||||
#include <string.h>
|
|
||||||
|
|
||||||
#include <unistd.h> // NOTE(yuval): Used for getcwd
|
#include <unistd.h> // NOTE(yuval): Used for getcwd
|
||||||
#include <dirent.h> // NOTE(yuval): Used for opendir, readdir
|
#include <dirent.h> // NOTE(yuval): Used for opendir, readdir
|
||||||
#include <sys/types.h> // NOTE(yuval): Used for struct stat
|
#include <sys/types.h> // NOTE(yuval): Used for struct stat
|
||||||
|
@ -97,9 +94,19 @@ mac_push_string_copy(Arena *arena, String_Const_u8 src){
|
||||||
external void
|
external void
|
||||||
mac_init(){
|
mac_init(){
|
||||||
Arena test_arena = make_arena_malloc();
|
Arena test_arena = make_arena_malloc();
|
||||||
system_get_file_list(&test_arena,
|
File_List list = system_get_file_list(&test_arena,
|
||||||
string_u8_litexpr("/Users/yuvaldolev/Desktop"));
|
string_u8_litexpr("/Users/yuvaldolev/Desktop"));
|
||||||
|
|
||||||
|
for (u32 index = 0; index < list.count; ++index) {
|
||||||
|
File_Info* info = list.infos[index];
|
||||||
|
|
||||||
|
printf("File_Info{file_name:'%.*s', "
|
||||||
|
"attributes:{size:%llu, last_write_time:%llu, flags:{IsDirectory:%d}}}\n",
|
||||||
|
(i32)info->file_name.size, info->file_name.str,
|
||||||
|
info->attributes.size, info->attributes.last_write_time,
|
||||||
|
((info->attributes.flags & FileAttribute_IsDirectory) != 0));
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
// NOTE(yuval): Context Setup
|
// NOTE(yuval): Context Setup
|
||||||
Thread_Context _tctx = {};
|
Thread_Context _tctx = {};
|
||||||
|
|
|
@ -107,85 +107,34 @@ system_get_file_list_sig(){
|
||||||
|
|
||||||
*file_path_at = 0;
|
*file_path_at = 0;
|
||||||
|
|
||||||
printf("File Path: %s ", file_path);
|
|
||||||
|
|
||||||
struct stat file_stat;
|
struct stat file_stat;
|
||||||
if (stat(file_path, &file_stat) == 0){
|
if (stat(file_path, &file_stat) == 0){
|
||||||
info->attributes.size = file_stat.st_size;
|
info->attributes.size = file_stat.st_size;
|
||||||
info->attributes.last_write_time = ;
|
info->attributes.last_write_time = file_stat.st_mtimespec.tv_sec;
|
||||||
info->attributes.flags = ;
|
info->attributes.flags = 0;
|
||||||
} else {
|
|
||||||
char* error_message = strerror(errno);
|
if (S_ISDIR(file_stat.st_mode)) {
|
||||||
printf("ERROR: stat failed with error message '%s'!\n", error_message);
|
info->attributes.flags |= FileAttribute_IsDirectory;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end_temp(temp);
|
end_temp(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*++file_count;
|
|
||||||
i32 size = 0;
|
|
||||||
for (; fname[size]; ++size);
|
|
||||||
character_count += size + 1;*/
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
i32 required_size = character_count + file_count * sizeof(File_Info);
|
|
||||||
if (file_list->block_size < required_size){
|
|
||||||
system_memory_free(file_list->block, file_list->block_size);
|
|
||||||
file_list->block = system_memory_allocate(required_size);
|
|
||||||
file_list->block_size = required_size;
|
|
||||||
}
|
|
||||||
|
|
||||||
file_list->infos = (File_Info*)file_list->block;
|
|
||||||
char *cursor = (char*)(file_list->infos + file_count);
|
|
||||||
|
|
||||||
if (file_list->block != 0){
|
|
||||||
rewinddir(d);
|
|
||||||
File_Info *info_ptr = file_list->infos;
|
|
||||||
for (struct dirent *entry = readdir(d);
|
|
||||||
entry != 0;
|
|
||||||
entry = readdir(d)){
|
|
||||||
char *fname = entry->d_name;
|
|
||||||
if (match(fname, ".") || match(fname, "..")){
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
char *cursor_start = cursor;
|
|
||||||
i32 length = copy_fast_unsafe_cc(cursor_start, fname);
|
|
||||||
cursor += length;
|
|
||||||
|
|
||||||
if (entry->d_type == DT_LNK){
|
|
||||||
struct stat st;
|
|
||||||
if (stat(entry->d_name, &st) != -1){
|
|
||||||
info_ptr->folder = S_ISDIR(st.st_mode);
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
info_ptr->folder = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
info_ptr->folder = (entry->d_type == DT_DIR);
|
|
||||||
}
|
|
||||||
|
|
||||||
info_ptr->filename = cursor_start;
|
|
||||||
info_ptr->filename_len = length;
|
|
||||||
*cursor++ = 0;
|
|
||||||
++info_ptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
file_list->count = file_count;
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
closedir(dir);
|
closedir(dir);
|
||||||
}
|
|
||||||
else{
|
|
||||||
|
|
||||||
/*system_memory_free(file_list->block, file_list->block_size);
|
result.infos = push_array(arena, File_Info*, count);
|
||||||
file_list->block = 0;
|
result.count = count;
|
||||||
file_list->block_size = 0;
|
|
||||||
file_list->infos = 0;
|
i32 index = 0;
|
||||||
file_list->count = 0;*/
|
for (File_Info* node = first;
|
||||||
|
node != 0;
|
||||||
|
node = node->next){
|
||||||
|
result.infos[index] = node;
|
||||||
|
index += 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return(result);
|
return(result);
|
||||||
|
|
Loading…
Reference in New Issue