aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Alc/alcConfig.c32
-rw-r--r--Alc/compat.h4
-rw-r--r--Alc/helpers.c97
3 files changed, 133 insertions, 0 deletions
diff --git a/Alc/alcConfig.c b/Alc/alcConfig.c
index 6fc9db33..f83ffd94 100644
--- a/Alc/alcConfig.c
+++ b/Alc/alcConfig.c
@@ -313,6 +313,7 @@ void ReadALConfig(void)
{
WCHAR buffer[PATH_MAX];
const WCHAR *str;
+ al_string ppath;
FILE *f;
if(SHGetSpecialFolderPathW(NULL, buffer, CSIDL_APPDATA, FALSE) != FALSE)
@@ -331,6 +332,19 @@ void ReadALConfig(void)
al_string_deinit(&filepath);
}
+ ppath = GetProcPath();
+ if(!al_string_empty(ppath))
+ {
+ al_string_append_cstr(&ppath, "\\alsoft.ini");
+ TRACE("Loading config %s...\n", al_string_get_cstr(ppath));
+ f = al_fopen(al_string_get_cstr(ppath), "r");
+ if(f)
+ {
+ LoadConfigFromFile(f);
+ fclose(f);
+ }
+ }
+
if((str=_wgetenv(L"ALSOFT_CONF")) != NULL && *str)
{
al_string filepath = AL_STRING_INIT_STATIC();
@@ -345,12 +359,15 @@ void ReadALConfig(void)
}
al_string_deinit(&filepath);
}
+
+ al_string_deinit(&ppath);
}
#else
void ReadALConfig(void)
{
char buffer[PATH_MAX];
const char *str;
+ al_string ppath;
FILE *f;
str = "/etc/openal/alsoft.conf";
@@ -430,6 +447,19 @@ void ReadALConfig(void)
}
}
+ ppath = GetProcPath();
+ if(!al_string_empty(ppath))
+ {
+ al_string_append_cstr(&ppath, "/alsoft.conf");
+ TRACE("Loading config %s...\n", al_string_get_cstr(ppath));
+ f = al_fopen(al_string_get_cstr(ppath), "r");
+ if(f)
+ {
+ LoadConfigFromFile(f);
+ fclose(f);
+ }
+ }
+
if((str=getenv("ALSOFT_CONF")) != NULL && *str)
{
TRACE("Loading config %s...\n", str);
@@ -440,6 +470,8 @@ void ReadALConfig(void)
fclose(f);
}
}
+
+ al_string_deinit(&ppath);
}
#endif
diff --git a/Alc/compat.h b/Alc/compat.h
index f54ef9ce..0443692a 100644
--- a/Alc/compat.h
+++ b/Alc/compat.h
@@ -1,6 +1,8 @@
#ifndef AL_COMPAT_H
#define AL_COMPAT_H
+#include "alstring.h"
+
#ifdef _WIN32
#define WIN32_LEAN_AND_MEAN
@@ -23,6 +25,8 @@ FILE *al_fopen(const char *fname, const char *mode);
#endif
+al_string GetProcPath(void);
+
#ifdef HAVE_DYNLOAD
void *LoadLib(const char *name);
void CloseLib(void *handle);
diff --git a/Alc/helpers.c b/Alc/helpers.c
index e1cd6be1..bd345b6a 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -321,6 +321,57 @@ static int StringSortCompare(const void *str1, const void *str2)
#ifdef _WIN32
+static WCHAR *strrchrW(WCHAR *str, WCHAR ch)
+{
+ WCHAR *ret = NULL;
+ while(*str)
+ {
+ if(*str == ch)
+ ret = str;
+ ++str;
+ }
+ return ret;
+}
+
+al_string GetProcPath(void)
+{
+ al_string ret = AL_STRING_INIT_STATIC();
+ WCHAR *pathname, *sep;
+ DWORD pathlen;
+ DWORD len;
+
+ pathlen = 256;
+ pathname = malloc(pathlen * sizeof(pathname[0]));
+ while(pathlen > 0 && (len=GetModuleFileNameW(NULL, pathname, pathlen)) == pathlen)
+ {
+ free(pathname);
+ pathlen <<= 1;
+ pathname = malloc(pathlen * sizeof(pathname[0]));
+ }
+ if(len == 0)
+ {
+ free(pathname);
+ ERR("Failed to get process name: error %lu\n", GetLastError());
+ return ret;
+ }
+
+ pathname[len] = 0;
+ if((sep = strrchrW(pathname, '\\')))
+ {
+ WCHAR *sep2 = strrchrW(pathname, '/');
+ if(sep2) *sep2 = 0;
+ else *sep = 0;
+ }
+ else if((sep = strrchrW(pathname, '/')))
+ *sep = 0;
+ al_string_copy_wcstr(&ret, pathname);
+ free(pathname);
+
+ TRACE("Got: %s\n", al_string_get_cstr(ret));
+ return ret;
+}
+
+
static WCHAR *FromUTF8(const char *str)
{
WCHAR *out = NULL;
@@ -549,6 +600,52 @@ vector_al_string SearchDataFiles(const char *ext, const char *subdir)
#else
+al_string GetProcPath(void)
+{
+ al_string ret = AL_STRING_INIT_STATIC();
+ const char *fname;
+ char *pathname, *sep;
+ size_t pathlen;
+ ssize_t len;
+
+ pathlen = 256;
+ pathname = malloc(pathlen);
+
+ fname = "/proc/self/exe";
+ len = readlink(fname, pathname, pathlen);
+ if(len == -1 && errno == ENOENT)
+ {
+ fname = "/proc/self/file";
+ len = readlink(fname, pathname, pathlen);
+ }
+
+ while(len > 0 && (size_t)len == pathlen)
+ {
+ free(pathname);
+ pathlen <<= 1;
+ pathname = malloc(pathlen);
+ len = readlink(fname, pathname, pathlen);
+ }
+ if(len <= 0)
+ {
+ free(pathname);
+ ERR("Failed to link %s: %s\n", fname, strerror(errno));
+ return ret;
+ }
+
+ pathname[len] = 0;
+ sep = strrchr(pathname, '/');
+ if(sep)
+ al_string_copy_range(&ret, pathname, sep);
+ else
+ al_string_copy_cstr(&ret, pathname);
+ free(pathname);
+
+ TRACE("Got: %s\n", al_string_get_cstr(ret));
+ return ret;
+}
+
+
#ifdef HAVE_DLFCN_H
void *LoadLib(const char *name)