bsnes-plus/common/nall/string/platform.hpp

48 lines
1.1 KiB
C++

#ifndef NALL_STRING_PLATFORM_HPP
#define NALL_STRING_PLATFORM_HPP
namespace nall {
string realpath(const char *name) {
char path[PATH_MAX];
if(::realpath(name, path)) {
string result(path);
result.transform("\\", "/");
if(result.endswith("/") == false) result.append("/");
return result;
}
return "";
}
string userpath() {
char path[PATH_MAX];
if(::userpath(path)) {
string result(path);
result.transform("\\", "/");
if(result.endswith("/") == false) result.append("/");
return result;
}
return "";
}
string currentpath() {
char path[PATH_MAX];
if(::getcwd(path)) {
string result(path);
result.transform("\\", "/");
if(result.endswith("/") == false) result.append("/");
return result;
}
return "";
}
//override filename's path with filepath, but only if filepath isn't empty
//used for GUI's "path selection" functionality
string filepath(const char *filename, const char *filepath) {
if(!filepath || !*filepath) return filename;
return string() << dir(filepath) << notdir(filename);
}
}
#endif