Newer
Older
Gigg, Martyn Anthony
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//-----------------------------
//Includes
//-----------------------------
#include "MantidKernel/System.h"
#include "Poco/Path.h"
// Need OS defined functions
#ifdef _WIN32
#include <windows.h>
#else
#include <unistd.h>
#endif
/**
* Get the directory containing the program executable
* @returns A string containing the path of the directory
* containing the executable, including a trailing slash
*/
std::string Mantid::Kernel::getDirectoryOfExecutable()
{
std::string execpath("");
const size_t LEN(1024);
char pBuf[LEN];
int bytes(0);
#ifdef _WIN32
bytes = GetModuleFileName(NULL, pBuf, LEN);
#else
char szTmp[32];
sprintf(szTmp, "/proc/%d/exe", getpid());
bytes = readlink(szTmp, pBuf, LEN);
#endif
if( bytes > 0 && bytes < 1024 )
{
pBuf[bytes] = '\0';
execpath = std::string(pBuf);
}
return Poco::Path(execpath).parent().toString();
}