added real_path function; bumped version to 1.1
This commit is contained in:
parent
66f0de4970
commit
6e0c828404
2
Makefile
2
Makefile
@ -1,6 +1,6 @@
|
||||
LIBNAME := $(shell basename $$(pwd))
|
||||
MAJOR := 1
|
||||
MINOR := 0.0
|
||||
MINOR := 1.0
|
||||
|
||||
UNAME_S := $(shell uname -s)
|
||||
|
||||
|
@ -198,11 +198,7 @@ string sc::filename_extension(const string& path) {
|
||||
|
||||
string sc::tool_path(const string& name) {
|
||||
if (name.find('/') != string::npos) { // name has (at least one) slash
|
||||
vector<char> buf;
|
||||
buf.resize(PATH_MAX);
|
||||
if (::realpath(name.c_str(), buf.data())) {
|
||||
return string(buf.data());
|
||||
}
|
||||
return sc::real_path(name);
|
||||
} else { // no slash in name => command from PATH?
|
||||
string envpath {::getenv("PATH")};
|
||||
vector<string> paths {sc::split(envpath, ":")};
|
||||
@ -259,3 +255,12 @@ bool sc::is_valid_utf8(const string& str) {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
string sc::real_path(const string& path) {
|
||||
vector<char> buf;
|
||||
buf.resize(PATH_MAX);
|
||||
if (::realpath(path.c_str(), buf.data())) {
|
||||
return string(buf.data());
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
@ -63,6 +63,7 @@ namespace sc {
|
||||
|
||||
bool is_valid_utf8 (const std::string& str);
|
||||
|
||||
std::string real_path (const std::string& path);
|
||||
}
|
||||
|
||||
#endif // _string_utils_
|
||||
|
Loading…
x
Reference in New Issue
Block a user