lib: Fix setting share dir
Setting from argv[0] seemed like a good idea at the time, but argv[0] can change based on how the user calls Ocarina (ocarina, ./ocarina, /usr/bin/ocarina, ...). This patch changes back to using the reliable /proc/self/exe method. Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
parent
9297f612de
commit
979de94712
14
lib/lib.cpp
14
lib/lib.cpp
|
@ -10,10 +10,16 @@ static std::string share_dir = "";
|
|||
|
||||
static void setup_share(const std::string &path)
|
||||
{
|
||||
if (path == "/usr/bin/ocarina")
|
||||
share_dir = "/usr/share/ocarina/";
|
||||
else
|
||||
share_dir = "./share/ocarina/";
|
||||
char buf[1024];
|
||||
ssize_t len = readlink("/proc/self/exe", buf, sizeof(buf) - 1);
|
||||
|
||||
if (len == -1)
|
||||
return;
|
||||
buf[len] = '\0';
|
||||
|
||||
share_dir = std::string(buf);
|
||||
share_dir = share_dir.substr(0, share_dir.size() - 11);
|
||||
share_dir = share_dir + "share/ocarina/";
|
||||
}
|
||||
|
||||
void lib :: init(int *argc, char ***argv, const std::string >k_xml)
|
||||
|
|
Loading…
Reference in New Issue