aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2014-02-27 01:49:23 -0800
committerChris Robinson <[email protected]>2014-02-27 01:49:23 -0800
commita8249c3469e1b0162030f767b5ffedc20c1622a4 (patch)
tree005e53add3c862f84fad9492e2afb50d4e99802f
parent3145bac8c6bf3f97f5232b801eb7ecac7f95e67f (diff)
Move OpenDataFile to helpers.c so other sources can use it
-rw-r--r--Alc/helpers.c133
-rw-r--r--Alc/hrtf.c131
-rw-r--r--OpenAL32/Include/alMain.h1
3 files changed, 134 insertions, 131 deletions
diff --git a/Alc/helpers.c b/Alc/helpers.c
index f8a5f13b..4b3973d9 100644
--- a/Alc/helpers.c
+++ b/Alc/helpers.c
@@ -18,12 +18,21 @@
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
+#ifdef _WIN32
+#ifdef __MINGW32__
+#define _WIN32_IE 0x501
+#else
+#define _WIN32_IE 0x400
+#endif
+#endif
+
#include "config.h"
#include <stdlib.h>
#include <time.h>
#include <errno.h>
#include <stdarg.h>
+#include <limits.h>
#ifdef HAVE_MALLOC_H
#include <malloc.h>
#endif
@@ -71,6 +80,10 @@ DEFINE_DEVPROPKEY(DEVPKEY_Device_FriendlyName, 0xa45c254e, 0xdf1c, 0x4efd, 0x80,
#include <ieeefp.h>
#endif
+#ifdef _WIN32_IE
+#include <shlobj.h>
+#endif
+
#include "alMain.h"
#include "atomic.h"
#include "uintmap.h"
@@ -94,6 +107,15 @@ extern inline ALint fastf2i(ALfloat f);
extern inline ALuint fastf2u(ALfloat f);
+#ifndef PATH_MAX
+#ifdef MAX_PATH
+#define PATH_MAX MAX_PATH
+#else
+#define PATH_MAX 4096
+#endif
+#endif
+
+
ALuint CPUCapFlags = 0;
@@ -501,6 +523,117 @@ void al_print(const char *type, const char *func, const char *fmt, ...)
}
+FILE *OpenDataFile(const char *fname, const char *subdir)
+{
+ char buffer[PATH_MAX] = "";
+ 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] == '/'))
+ {
+ if((f=fopen(fname, "rb")) != NULL)
+ {
+ TRACE("Opened %s\n", fname);
+ return f;
+ }
+ WARN("Could not open %s\n", fname);
+ return NULL;
+ }
+
+ for(i = 0;i < 2;i++)
+ {
+ size_t len;
+
+ 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] = '\\';
+ }
+
+ 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;
+
+ if(fname[0] == '/')
+ {
+ if((f=fopen(fname, "rb")) != NULL)
+ {
+ TRACE("Opened %s\n", fname);
+ 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')
+ snprintf(buffer, sizeof(buffer), "%s/.local/share/%s/%s", str, subdir, fname);
+ if(buffer[0])
+ {
+ if((f=fopen(buffer, "rb")) != NULL)
+ {
+ TRACE("Opened %s\n", buffer);
+ return f;
+ }
+ WARN("Could not open %s\n", buffer);
+ }
+
+ if((str=getenv("XDG_DATA_DIRS")) == NULL || str[0] == '\0')
+ str = " /usr/local/share/:/usr/share/";
+
+ next = str;
+ while((str=next) != NULL && str[0] != '\0')
+ {
+ size_t len;
+ next = strchr(str, ':');
+
+ if(!next)
+ len = strlen(str);
+ else
+ {
+ len = next - str;
+ next++;
+ }
+
+ if(len > sizeof(buffer)-1)
+ len = sizeof(buffer)-1;
+ strncpy(buffer, str, len);
+ buffer[len] = '\0';
+ snprintf(buffer+len, sizeof(buffer)-len, "/%s/%s", subdir, fname);
+
+ if((f=fopen(buffer, "rb")) != NULL)
+ {
+ TRACE("Opened %s\n", buffer);
+ return f;
+ }
+ WARN("Could not open %s\n", buffer);
+ }
+#endif
+
+ return NULL;
+}
+
+
void SetRTPriority(void)
{
ALboolean failed = AL_FALSE;
diff --git a/Alc/hrtf.c b/Alc/hrtf.c
index 649f5700..a0f8833b 100644
--- a/Alc/hrtf.c
+++ b/Alc/hrtf.c
@@ -18,23 +18,10 @@
* Or go to http://www.gnu.org/copyleft/lgpl.html
*/
-#ifdef _WIN32
-#ifdef __MINGW32__
-#define _WIN32_IE 0x501
-#else
-#define _WIN32_IE 0x400
-#endif
-#endif
-
#include "config.h"
#include <stdlib.h>
#include <ctype.h>
-#include <limits.h>
-
-#ifdef _WIN32_IE
-#include <shlobj.h>
-#endif
#include "AL/al.h"
#include "AL/alc.h"
@@ -44,15 +31,6 @@
#include "hrtf.h"
-#ifndef PATH_MAX
-#ifdef MAX_PATH
-#define PATH_MAX MAX_PATH
-#else
-#define PATH_MAX 4096
-#endif
-#endif
-
-
/* Current data set limits defined by the makehrtf utility. */
#define MIN_IR_SIZE (8)
#define MAX_IR_SIZE (128)
@@ -669,115 +647,6 @@ static struct Hrtf *LoadHrtf01(FILE *f, ALuint deviceRate)
return NULL;
}
-static FILE *OpenDataFile(const char *fname, const char *subdir)
-{
- char buffer[PATH_MAX] = "";
- 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] == '/'))
- {
- if((f=fopen(fname, "rb")) != NULL)
- {
- TRACE("Opened %s\n", fname);
- return f;
- }
- WARN("Could not open %s\n", fname);
- return NULL;
- }
-
- for(i = 0;i < 2;i++)
- {
- size_t len;
-
- 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] = '\\';
- }
-
- 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;
-
- if(fname[0] == '/')
- {
- if((f=fopen(fname, "rb")) != NULL)
- {
- TRACE("Opened %s\n", fname);
- 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')
- snprintf(buffer, sizeof(buffer), "%s/.local/share/%s/%s", str, subdir, fname);
- if(buffer[0])
- {
- if((f=fopen(buffer, "rb")) != NULL)
- {
- TRACE("Opened %s\n", buffer);
- return f;
- }
- WARN("Could not open %s\n", buffer);
- }
-
- if((str=getenv("XDG_DATA_DIRS")) == NULL || str[0] == '\0')
- str = " /usr/local/share/:/usr/share/";
-
- next = str;
- while((str=next) != NULL && str[0] != '\0')
- {
- size_t len;
- next = strchr(str, ':');
-
- if(!next)
- len = strlen(str);
- else
- {
- len = next - str;
- next++;
- }
-
- if(len > sizeof(buffer)-1)
- len = sizeof(buffer)-1;
- strncpy(buffer, str, len);
- buffer[len] = '\0';
- snprintf(buffer+len, sizeof(buffer)-len, "/%s/%s", subdir, fname);
-
- if((f=fopen(buffer, "rb")) != NULL)
- {
- TRACE("Opened %s\n", buffer);
- return f;
- }
- WARN("Could not open %s\n", buffer);
- }
-#endif
-
- return NULL;
-}
static struct Hrtf *LoadHrtf(ALuint deviceRate)
{
diff --git a/OpenAL32/Include/alMain.h b/OpenAL32/Include/alMain.h
index 3aa9166a..e6050b7f 100644
--- a/OpenAL32/Include/alMain.h
+++ b/OpenAL32/Include/alMain.h
@@ -844,6 +844,7 @@ enum {
void FillCPUCaps(ALuint capfilter);
+FILE *OpenDataFile(const char *fname, const char *subdir);
/* Small hack to use a pointer-to-array type as a normal argument type.
* Shouldn't be used directly. */