Add fill_pathname_parent_dir.

This commit is contained in:
Themaister 2012-11-25 16:22:53 +01:00
parent df40f854cd
commit 8b09314aa3
3 changed files with 23 additions and 1 deletions

View File

@ -95,7 +95,7 @@ static bool filebrowser_pop_directory (filebrowser_t * filebrowser)
if (filebrowser->directory_stack_size > 0)
pop_dir -= 1;
fill_pathname_basedir(previous_dir, filebrowser->directory_path, sizeof(previous_dir));
fill_pathname_parent_dir(previous_dir, filebrowser->directory_path, sizeof(previous_dir));
strlcpy(directory_path_tmp, filebrowser->directory_path, sizeof(directory_path_tmp));
//test first if previous directory can be accessed

8
file.h
View File

@ -75,6 +75,10 @@ const char *path_basename(const char *path);
// Extracts base directory by mutating path. Keeps trailing '/'.
void path_basedir(char *path);
// Extracts parent directory by mutating path.
// Assumes that path is a directory. Keeps trailing '/'.
void path_parent_dir(char *path);
bool path_is_absolute(const char *path);
// Path-name operations.
@ -108,6 +112,10 @@ void fill_pathname_base(char *out_path, const char *in_path, size_t size);
// If in_path is a path without any slashes (relative current directory), out_path will get path "./".
void fill_pathname_basedir(char *out_path, const char *in_path, size_t size);
// Copies parent directory of in_dir into out_dir.
// Assumes in_dir is a directory. Keeps trailing '/'.
void fill_pathname_parent_dir(char *out_dir, const char *in_dir, size_t size);
// Joins basedir of in_refpath together with in_path.
// If in_path is an absolute path, out_path = in_path.
// E.g.: in_refpath = "/foo/bar/baz.a", in_path = "foobar.cg", out_path = "/foo/bar/foobar.cg".

View File

@ -429,6 +429,12 @@ void fill_pathname_basedir(char *out_dir, const char *in_path, size_t size)
path_basedir(out_dir);
}
void fill_pathname_parent_dir(char *out_dir, const char *in_dir, size_t size)
{
rarch_assert(strlcpy(out_dir, in_dir, size) < size);
path_parent_dir(out_dir);
}
void path_basedir(char *path)
{
if (strlen(path) < 2)
@ -450,6 +456,14 @@ void path_basedir(char *path)
}
}
void path_parent_dir(char *path)
{
size_t len = strlen(path);
if (len && ((path[len - 1] == '/') || (path[len - 1] == '\\')))
path[len - 1] = '\0';
path_basedir(path);
}
const char *path_basename(const char *path)
{
const char *last = strrchr(path, '/');