GPAK  1.0.0
A general-purpose archive library

◆ filesystem_tree_find_directory()

GPAK_API filesystem_tree_node_t* filesystem_tree_find_directory ( filesystem_tree_node_t _root,
const char *  _path 
)
Brief Description:\n Finds a directory in the filesystem tree.

This function searches for a directory node with the specified path in the filesystem tree.

Parameters
_rootA pointer to the root filesystem_tree_node_t.
_pathThe path of the directory to find.
Returns
A pointer to the found directory node or NULL if not found.

Definition at line 164 of file filesystem_tree.c.

165 {
166  if (!_root || !_path || !*_path)
167  return NULL;
168 
169  char* dir_path = strdup(_path);
170  char* dir_name = strtok(dir_path, "/");
171 
172  filesystem_tree_node_t* current = _root;
173  while (dir_name)
174  {
175  current = _find_directory(current, dir_name);
176  if (!current)
177  break;
178  dir_name = strtok(NULL, "/");
179  }
180 
181  free(dir_path);
182  return current;
183 }

Referenced by gpak_find_directory().