Fix compilation by adding forgotten comma.
[mplayer/glamo.git] / get_path.c
blob952979bbe7e9ee0ed7bad45f5f5f556521ae6d0a
2 /*
3 * Get path to config dir/file.
5 * Return Values:
6 * Returns the pointer to the ALLOCATED buffer containing the
7 * zero terminated path string. This buffer has to be FREED
8 * by the caller.
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <string.h>
15 #include "mp_msg.h"
17 #ifdef MACOSX_BUNDLE
18 #include <CoreFoundation/CoreFoundation.h>
19 #include <sys/types.h>
20 #include <sys/stat.h>
21 #include <unistd.h>
22 #endif
24 char *get_path(const char *filename){
25 char *homedir;
26 char *buff;
27 #if defined(__MINGW32__)
28 static char *config_dir = "/mplayer";
29 #else
30 static char *config_dir = "/.mplayer";
31 #endif
32 int len;
33 #ifdef MACOSX_BUNDLE
34 struct stat dummy;
35 CFIndex maxlen=256;
36 CFURLRef res_url_ref=NULL;
37 CFURLRef bdl_url_ref=NULL;
38 char *res_url_path = NULL;
39 char *bdl_url_path = NULL;
40 #endif
42 if ((homedir = getenv("MPLAYER_HOME")) != NULL)
43 config_dir = "";
44 else if ((homedir = getenv("HOME")) == NULL)
45 #if defined(__MINGW32__)||defined(__CYGWIN__) /*hack to get fonts etc. loaded outside of cygwin environment*/
47 int i,imax=0;
48 char exedir[260];
49 GetModuleFileNameA(NULL, exedir, 260);
50 for(i=0; i< strlen(exedir);i++)if(exedir[i] =='\\'){exedir[i]='/';imax=i;}
51 exedir[imax]='\0';
52 homedir = exedir;
54 #else
55 return NULL;
56 #endif
57 len = strlen(homedir) + strlen(config_dir) + 1;
58 if (filename == NULL) {
59 if ((buff = malloc(len)) == NULL)
60 return NULL;
61 sprintf(buff, "%s%s", homedir, config_dir);
62 } else {
63 len += strlen(filename) + 1;
64 if ((buff = malloc(len)) == NULL)
65 return NULL;
66 sprintf(buff, "%s%s/%s", homedir, config_dir, filename);
69 #ifdef MACOSX_BUNDLE
70 if(stat(buff, &dummy)) {
72 res_url_ref=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
73 bdl_url_ref=CFBundleCopyBundleURL(CFBundleGetMainBundle());
75 if(res_url_ref&&bdl_url_ref) {
77 res_url_path=malloc(maxlen);
78 bdl_url_path=malloc(maxlen);
80 while(!CFURLGetFileSystemRepresentation(res_url_ref, true, res_url_path, maxlen)) {
81 maxlen*=2;
82 res_url_path=realloc(res_url_path, maxlen);
84 CFRelease(res_url_ref);
86 while(!CFURLGetFileSystemRepresentation(bdl_url_ref, true, bdl_url_path, maxlen)) {
87 maxlen*=2;
88 bdl_url_path=realloc(bdl_url_path, maxlen);
90 CFRelease(bdl_url_ref);
92 if( strcmp(res_url_path, bdl_url_path) == 0)
93 res_url_path = NULL;
96 if(res_url_path&&filename) {
97 if((strlen(filename)+strlen(res_url_path)+2)>maxlen) {
98 maxlen=strlen(filename)+strlen(res_url_path)+2;
100 free(buff);
101 buff = malloc(maxlen);
102 strcpy(buff, res_url_path);
104 strcat(buff,"/");
105 strcat(buff, filename);
108 #endif
109 mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff);
110 return buff;
113 #if defined(WIN32) && defined(USE_WIN32DLL)
114 void set_path_env()
116 /*make our codec dirs available for LoadLibraryA()*/
117 char tmppath[MAX_PATH*2 + 1];
118 char win32path[MAX_PATH];
119 char realpath[MAX_PATH];
120 #ifdef __CYGWIN__
121 cygwin_conv_to_full_win32_path(WIN32_PATH,win32path);
122 strcpy(tmppath,win32path);
123 #ifdef USE_REALCODECS
124 cygwin_conv_to_full_win32_path(REALCODEC_PATH,realpath);
125 sprintf(tmppath,"%s;%s",win32path,realpath);
126 #endif /*USE_REALCODECS*/
127 #else /*__CYGWIN__*/
128 /* Expand to absolute path unless it's already absolute */
129 if(!strstr(WIN32_PATH,":") && WIN32_PATH[0] != '\\'){
130 GetModuleFileNameA(NULL, win32path, MAX_PATH);
131 strcpy(strrchr(win32path, '\\') + 1, WIN32_PATH);
133 else strcpy(win32path,WIN32_PATH);
134 strcpy(tmppath,win32path);
135 #ifdef USE_REALCODECS
136 /* Expand to absolute path unless it's already absolute */
137 if(!strstr(REALCODEC_PATH,":") && REALCODEC_PATH[0] != '\\'){
138 GetModuleFileNameA(NULL, realpath, MAX_PATH);
139 strcpy(strrchr(realpath, '\\') + 1, REALCODEC_PATH);
141 else strcpy(realpath,REALCODEC_PATH);
142 sprintf(tmppath,"%s;%s",win32path,realpath);
143 #endif /*USE_REALCODECS*/
144 #endif /*__CYGWIN__*/
145 mp_msg(MSGT_WIN32, MSGL_V,"Setting PATH to %s\n",tmppath);
146 if (!SetEnvironmentVariableA("PATH", tmppath))
147 mp_msg(MSGT_WIN32, MSGL_WARN, "Cannot set PATH!");
149 #endif /*WIN32 && USE_WIN32DLL*/