mufs: clean up code in resolve_path()

tags/0.1.0
S.J.R. van Schaik 8 years ago
parent 52b382b8b0
commit 9f05686a1f
  1. 37
      source/fs/mufs/dir.c

@ -95,22 +95,24 @@ err_free_dir:
struct mufs_tree *resolve_path(struct mufs *fs, const char *path) struct mufs_tree *resolve_path(struct mufs *fs, const char *path)
{ {
struct mufs_dir *dir; struct mufs_dir *dir = NULL;
struct mufs_dirent entry; struct mufs_dirent entry, *found = NULL;
struct mufs_tree *tree; struct mufs_tree *tree = NULL;
char *s, *p, *end; char *s, *p, *end;
int ret; int ret;
if (!(s = mufs_abspath(path))) if (!(s = mufs_abspath(path)))
return NULL; return NULL;
if (strcmp(s, "/") == 0) if (strcmp(s, "/") == 0) {
return &fs->root; tree = &fs->root;
if (!(dir = open_dirent(fs, NULL)))
goto err_free_s; goto err_free_s;
}
for (p = s + 1; *p != '\0'; p = end) { for (p = s + 1; *p != '\0'; p = end) {
if (!(dir = open_dirent(fs, found)))
goto err_free_s;
end = p + strcspn(p, "/"); end = p + strcspn(p, "/");
if (*end == '/') if (*end == '/')
@ -120,29 +122,22 @@ struct mufs_tree *resolve_path(struct mufs *fs, const char *path)
if (strcmp(entry.path, p) != 0) if (strcmp(entry.path, p) != 0)
continue; continue;
mufs_closedir(dir); found = &entry;
if (!(dir = open_dirent(fs, &entry)))
goto err_free_s;
break; break;
} }
if (ret < 0) if (ret < 0)
goto err_close_dir; goto err_closedir;
}
tree = dir->tree; tree = dir->tree;
dir->tree = NULL;
mufs_closedir(dir); }
return tree;
err_close_dir: err_closedir:
mufs_closedir(dir); mufs_closedir(dir);
err_free_s: err_free_s:
free(s); free(s);
return NULL; return tree;
} }
struct mufs_dir *mufs_opendir(struct mufs *fs, const char *path) struct mufs_dir *mufs_opendir(struct mufs *fs, const char *path)

Loading…
Cancel
Save