aboutsummaryrefslogtreecommitdiffstats
path: root/Alc/helpers.c
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-01-13 04:40:20 -0800
committerChris Robinson <[email protected]>2018-01-13 04:40:20 -0800
commitc031b3cc6a8bb1525b59a850d3d8c6e4541256ce (patch)
tree59855fe52ead07739f0bddc67da0d2ff8439c268 /Alc/helpers.c
parentbbc4ebecabc9417f92fbc9a185edf7360f1a8b6e (diff)
Avoid fixed-PATH_MAX-size buffers
Windows still needs to use MAX_PATH in a couple places, but that macro's guaranteed there.
Diffstat (limited to 'Alc/helpers.c')
-rw-r--r--Alc/helpers.c27
1 files changed, 22 insertions, 5 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index 790484e9..96f9b681 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -642,7 +642,7 @@ vector_al_string SearchDataFiles(const char *ext, const char *subdir)
/* Search the local and global data dirs. */
for(i = 0;i < COUNTOF(ids);i++)
{
- WCHAR buffer[PATH_MAX];
+ WCHAR buffer[MAX_PATH];
if(SHGetSpecialFolderPathW(NULL, buffer, ids[i], FALSE) != FALSE)
{
alstr_copy_wcstr(&path, buffer);
@@ -907,15 +907,32 @@ vector_al_string SearchDataFiles(const char *ext, const char *subdir)
{
al_string path = AL_STRING_INIT_STATIC();
const char *str, *next;
- char cwdbuf[PATH_MAX];
/* Search the app-local directory. */
if((str=getenv("ALSOFT_LOCAL_PATH")) && *str != '\0')
DirectorySearch(str, ext, &results);
- else if(getcwd(cwdbuf, sizeof(cwdbuf)))
- DirectorySearch(cwdbuf, ext, &results);
else
- DirectorySearch(".", ext, &results);
+ {
+ size_t cwdlen = 256;
+ char *cwdbuf = malloc(cwdlen);
+ while(!getcwd(cwdbuf, cwdlen))
+ {
+ free(cwdbuf);
+ cwdbuf = NULL;
+ if(errno != ERANGE)
+ break;
+ cwdlen <<= 1;
+ cwdbuf = malloc(cwdlen);
+ }
+ if(!cwdbuf)
+ DirectorySearch(".", ext, &results);
+ else
+ {
+ DirectorySearch(cwdbuf, ext, &results);
+ free(cwdbuf);
+ cwdbuf = NULL;
+ }
+ }
// Search local data dir
if((str=getenv("XDG_DATA_HOME")) != NULL && str[0] != '\0')