X-Git-Url: http://git.tdb.fi/?p=libs%2Fcore.git;a=blobdiff_plain;f=source%2Ffs%2Fdir.cpp;h=218a7a5cf75e0b8a1a05576bf4d5893423f02ec9;hp=3811c3f447f7f4b0b7677b17be8ce4d0f454f82a;hb=f804a61c1c58529e7c98555a921b56bc05059d5e;hpb=8bbba6b8cd02c33612fb173e6df48b130407af8f diff --git a/source/fs/dir.cpp b/source/fs/dir.cpp index 3811c3f..218a7a5 100644 --- a/source/fs/dir.cpp +++ b/source/fs/dir.cpp @@ -1,7 +1,6 @@ -#include -#include #include #include +#include #include #include #include @@ -38,16 +37,18 @@ const Path &get_bin_dir(const string &argv0) { Path exe; if(argv0.find(DIRSEP)==string::npos) - if(const char *path = getenv("PATH")) + { + string path = getenv("PATH"); + if(!path.empty()) { - vector dirs = split(path, ITEMSEP); - for(vector::const_iterator i=dirs.begin(); i!=dirs.end(); ++i) - if(exists(Path(*i)/argv0)) + for(const string &d: split(path, ITEMSEP)) + if(exists(Path(d)/argv0)) { - exe = realpath(Path(*i)/argv0); + exe = realpath(Path(d)/argv0); break; } } + } if(exe.empty()) exe = realpath(argv0); @@ -70,9 +71,9 @@ not_a_directory::not_a_directory(const Path &p): void mkpath(const Path &path, int mode) { Path p; - for(Path::Iterator i=path.begin(); i!=path.end(); ++i) + for(const string &c: path) { - p /= *i; + p /= c; #ifdef _WIN32 if(p.size()==1 && p.is_absolute()) continue; @@ -90,10 +91,9 @@ void mkpath(const Path &path, int mode) void rmpath(const Path &path) { - list files = list_files(path); - for(list::iterator i=files.begin(); i!=files.end(); ++i) + for(const string &f: list_files(path)) { - Path p = path / *i; + Path p = path/f; if(is_dir(p)) rmpath(p); else @@ -103,16 +103,16 @@ void rmpath(const Path &path) rmdir(path); } -list list_files(const Path &path) +vector list_files(const Path &path) { return list_filtered(path, string()); } -list list_filtered(const Path &path, const string &filter) +vector list_filtered(const Path &path, const string &filter) { Regex r_filter(filter); - list result; + vector result; DIR *dir = opendir(path.str().c_str()); if(!dir) throw system_error("opendir"); @@ -130,11 +130,6 @@ list list_filtered(const Path &path, const string &filter) return result; } -Path get_sys_conf_dir(const string &) -{ - return get_sys_conf_dir(); -} - Path get_sys_conf_dir() { const char *argv0 = Application::get_argv0(); @@ -154,11 +149,6 @@ Path get_sys_conf_dir() return dir; } -Path get_sys_data_dir(const string &, const string &) -{ - return get_sys_data_dir(); -} - Path get_sys_data_dir() { const char *argv0 = Application::get_argv0(); @@ -175,11 +165,6 @@ Path get_sys_data_dir() return dir; } -Path get_sys_lib_dir(const string &, const string &) -{ - return get_sys_lib_dir(); -} - Path get_sys_lib_dir() { const char *argv0 = Application::get_argv0(); @@ -194,11 +179,11 @@ Path get_sys_lib_dir() return dir; } -Path path_lookup(const string &name, const list &paths) +Path path_lookup(const string &name, const vector &paths) { - for(list::const_iterator i=paths.begin(); i!=paths.end(); ++i) + for(const Path &p: paths) { - Path full = *i/name; + Path full = p/name; if(exists(full)) return realpath(full); } @@ -208,9 +193,9 @@ Path path_lookup(const string &name, const list &paths) Path path_lookup(const string &name) { - const char *path = getenv("PATH"); + string path = getenv("PATH"); vector dirs = split(path, ITEMSEP); - return path_lookup(name, list(dirs.begin(), dirs.end())); + return path_lookup(name, vector(dirs.begin(), dirs.end())); } } // namespace FS