| 534 | /////////////////////////////////////////// |
| 535 | |
| 536 | void platform_iterate_dir(const char *directory_path, void *callback_data, void (*on_item)(void *callback_data, const char *name, const platform_file_attr_t file_attr)) { |
| 537 | if (string_eq(directory_path, "")) { |
| 538 | directory_path = platform_path_separator; |
| 539 | } |
| 540 | |
| 541 | DIR *dir; |
| 542 | struct dirent *dir_info; |
| 543 | dir = opendir(directory_path); |
| 544 | if (!dir) return; |
| 545 | |
| 546 | while ((dir_info = readdir(dir)) != nullptr) { |
| 547 | if (string_eq(dir_info->d_name, ".") || string_eq(dir_info->d_name, "..")) continue; |
| 548 | platform_file_attr_t file_attr; |
| 549 | if (dir_info->d_type == DT_DIR) { |
| 550 | file_attr.size = 0; |
| 551 | file_attr.file = false; |
| 552 | on_item(callback_data, dir_info->d_name, file_attr); |
| 553 | } |
| 554 | else if (dir_info->d_type == DT_REG) { |
| 555 | char* file_path = new char[strlen(directory_path) + strlen(dir_info->d_name) + 1]; |
| 556 | strcpy(file_path, directory_path); |
| 557 | strcat(file_path, "/"); |
| 558 | strcat(file_path, dir_info->d_name); |
| 559 | struct stat file_stat; |
| 560 | stat(file_path, &file_stat); |
| 561 | free(file_path); |
| 562 | platform_file_attr_t file_attr; |
| 563 | file_attr.size = file_stat.st_size; |
| 564 | on_item(callback_data, dir_info->d_name, file_attr); |
| 565 | } |
| 566 | } |
| 567 | closedir(dir); |
| 568 | } |
| 569 | |
| 570 | /////////////////////////////////////////// |
| 571 | |