Create a file tree entry by checking if a path is a file and counting dir children. */
| 9714 | |
| 9715 | /* Create a file tree entry by checking if a path is a file and counting dir children. */ |
| 9716 | static cbm_file_tree_entry_t make_tree_entry(const char *path, char **files, int fn, |
| 9717 | char **dir_paths, const int *dir_child_counts, |
| 9718 | int dn) { |
| 9719 | cbm_file_tree_entry_t e = {0}; |
| 9720 | e.path = heap_strdup(path); |
| 9721 | bool is_file = false; |
| 9722 | for (int f = 0; f < fn; f++) { |
| 9723 | if (strcmp(files[f], path) == 0) { |
| 9724 | is_file = true; |
| 9725 | break; |
| 9726 | } |
| 9727 | } |
| 9728 | e.type = heap_strdup(is_file ? "file" : "dir"); |
| 9729 | for (int d = 0; d < dn; d++) { |
| 9730 | if (strcmp(dir_paths[d], path) == 0) { |
| 9731 | e.children = dir_child_counts[d]; |
| 9732 | break; |
| 9733 | } |
| 9734 | } |
| 9735 | return e; |
| 9736 | } |
| 9737 | |
| 9738 | /* Split a path by '/' into parts. Returns number of parts. */ |
| 9739 | static int split_path_parts(const char *fp, char *buf, int buf_sz, char **parts, int max_parts) { |
no test coverage detected