diff options
author | Chris Robinson <[email protected]> | 2014-02-26 17:38:19 -0800 |
---|---|---|
committer | Chris Robinson <[email protected]> | 2014-02-26 17:38:19 -0800 |
commit | 99d82690efa6d00a325f7e2ae7d13edf80b6db67 (patch) | |
tree | 5290f4e3342497b6e6e74c5447c485ad66e72b93 | |
parent | 1b9a722601e59baa1f78cc42f39df40bc6fb9cf6 (diff) |
Don't fallback to relative filename handling if opening as absolute fails
-rw-r--r-- | Alc/hrtf.c | 53 |
1 files changed, 27 insertions, 26 deletions
@@ -675,6 +675,9 @@ static FILE *OpenDataFile(const char *fname, const char *subdir) FILE *f; #ifdef _WIN32 + static const int ids[2] = { CSIDL_APPDATA, CSIDL_COMMON_APPDATA }; + int i; + /* If the path is absolute, open it directly. */ if(fname[0] != '\0' && fname[1] == ':' && (fname[2] == '\\' || fname[2] == '/')) { @@ -684,38 +687,34 @@ static FILE *OpenDataFile(const char *fname, const char *subdir) return f; } WARN("Could not open %s\n", fname); + return NULL; } - else - { - static const int ids[2] = { CSIDL_APPDATA, CSIDL_COMMON_APPDATA }; - int i; - for(i = 0;i < 2;i++) - { - size_t len; + for(i = 0;i < 2;i++) + { + size_t len; - if(SHGetSpecialFolderPathA(NULL, buffer, ids[i], FALSE) == FALSE) - continue; + if(SHGetSpecialFolderPathA(NULL, buffer, ids[i], FALSE) == FALSE) + continue; - len = strlen(buffer); - if(len > 0 && (buffer[len-1] == '\\' || buffer[len-1] == '/')) - buffer[--len] = '\0'; - snprintf(buffer+len, sizeof(buffer)-len, "/%s/%s", subdir, fname); - len = strlen(buffer); - while(len > 0) - { - --len; - if(buffer[len] == '/') - buffer[len] = '\\'; - } + len = strlen(buffer); + if(len > 0 && (buffer[len-1] == '\\' || buffer[len-1] == '/')) + buffer[--len] = '\0'; + snprintf(buffer+len, sizeof(buffer)-len, "/%s/%s", subdir, fname); + len = strlen(buffer); + while(len > 0) + { + --len; + if(buffer[len] == '/') + buffer[len] = '\\'; + } - if((f=fopen(buffer, "rb")) != NULL) - { - TRACE("Opened %s\n", buffer); - return f; - } - WARN("Could not open %s\n", buffer); + if((f=fopen(buffer, "rb")) != NULL) + { + TRACE("Opened %s\n", buffer); + return f; } + WARN("Could not open %s\n", buffer); } #else const char *str, *next; @@ -728,7 +727,9 @@ static FILE *OpenDataFile(const char *fname, const char *subdir) return f; } WARN("Could not open %s\n", fname); + return NULL; } + if((str=getenv("XDG_DATA_HOME")) != NULL && str[0] != '\0') snprintf(buffer, sizeof(buffer), "%s/%s/%s", str, subdir, fname); else if((str=getenv("HOME")) != NULL && str[0] != '\0') |