Update functions

This commit is contained in:
blahpy
2020-09-10 22:07:23 +12:00
parent efe94dca79
commit 369a1031e1
2 changed files with 20 additions and 11 deletions
+18 -9
View File
@@ -3,22 +3,31 @@
#include <stdio.h> /* defines FILENAME_MAX */
#ifdef _WIN32
#include <direct.h>
#define GetCurrentDir _getcwd
#include <Windows.h>
#else
#include <unistd.h>
#define GetCurrentDir getcwd
#endif
std::string FileUtil::GetCurrentWorkingDir() {
char buff[FILENAME_MAX];
GetCurrentDir(buff, FILENAME_MAX);
std::string current_working_dir(buff);
return current_working_dir;
std::string FileUtil::GetExecutablePath() {
#ifdef _WIN32
char buffer[FILENAME_MAX];
GetModuleFileNameA(NULL, buffer, FILENAME_MAX);
std::string::size_type pos =
std::string(buffer).find_last_of("/\\"); // Strip executable from file path
return std::string(buffer).substr(0, pos);
#else // do Linux stuff
char buffer[FILENAME_MAX];
readlink("/proc/self/exe", buffer,
FILENAME_MAX); // /proc/self acts like a "virtual folder" containing information about
// the current process
std::string::size_type pos =
std::string(buffer).find_last_of("/\\"); // Strip executable from file path
return std::string(buffer).substr(0, pos);
#endif
}
std::string FileUtil::get_file_path(const std::vector<std::string>& input) {
std::string currentPath = FileUtil::GetCurrentWorkingDir(); // std::filesystem::current_path();
std::string currentPath = FileUtil::GetExecutablePath();
char dirSeparator;
#ifdef _WIN32
+2 -2
View File
@@ -3,6 +3,6 @@
#include <vector>
namespace FileUtil {
std::string GetCurrentWorkingDir();
std::string get_file_path(std::vector<std::string> input);
std::string GetExecutablePath();
std::string get_file_path(const std::vector<std::string>& input);
} // namespace FileUtil