You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
48 lines
751 B
48 lines
751 B
#pragma once |
|
|
|
#include <string> |
|
|
|
#ifdef _WIN32 |
|
|
|
#include <windows.h> |
|
|
|
#ifndef PATH_MAX |
|
#define PATH_MAX 4096 |
|
#endif |
|
|
|
namespace nxl::os { |
|
|
|
std::string getApplicationDirectory() |
|
{ |
|
char exePath[PATH_MAX]; |
|
GetModuleFileNameA(NULL, exePath, PATH_MAX); |
|
std::string exeDir = std::string(dirname(exePath)); |
|
return exeDir; |
|
} |
|
|
|
} // namespace nxl::os |
|
|
|
#else |
|
#include <sys/types.h> |
|
#include <unistd.h> |
|
#include <libgen.h> |
|
|
|
namespace nxl::os { |
|
|
|
std::string getApplicationDirectory() |
|
{ |
|
char result[PATH_MAX] = {0}; |
|
std::string path; |
|
ssize_t count = readlink("/proc/self/exe", result, PATH_MAX); |
|
if (count != -1) { |
|
result[count] = '\0'; |
|
path = dirname(result); |
|
} else { |
|
path = "./"; |
|
} |
|
return path; |
|
} |
|
|
|
} // namespace nxl::os |
|
|
|
#endif
|
|
|