GPAK  1.0.0
A general-purpose archive library

◆ filesystem_tree_add_directory()

GPAK_API void filesystem_tree_add_directory ( filesystem_tree_node_t _root,
const char *  _path 
)
Brief Description:\n Adds a directory to the filesystem tree.

This function creates a new directory node under the given _root node.

Parameters
_rootA pointer to the root filesystem_tree_node_t.
_pathThe path of the directory to add.

Definition at line 110 of file filesystem_tree.c.

111 {
112  if (!_root || !_path || !*_path)
113  return;
114 
115  char* dir_path = strdup(_path);
116  char* dir_name = strtok(dir_path, "/");
117 
118  filesystem_tree_node_t* current = _root;
119  while (dir_name)
120  {
121  filesystem_tree_node_t* found = _find_directory(current, dir_name);
122  if (!found)
123  found = _add_directory(current, dir_name);
124 
125  current = found;
126  dir_name = strtok(NULL, "/");
127  }
128 
129  free(dir_path);
130 }

Referenced by gpak_add_directory().