annotate get_path.c @ 16176:05716caa47e4

synced with 1.87
author gabrov
date Fri, 05 Aug 2005 21:13:13 +0000
parents 4be161b8e0ef
children 6809ca5dd307
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
1
12891
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
2 /*
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
3 * Get path to config dir/file.
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
4 *
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
5 * Return Values:
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
6 * Returns the pointer to the ALLOCATED buffer containing the
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
7 * zero terminated path string. This buffer has to be FREED
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
8 * by the caller.
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
9 *
54ea3d6e657c added src level documentation for the get_path() function
al
parents: 12358
diff changeset
10 */
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
11 #ifdef MACOSX_BUNDLE
15237
55d9619d75e5 replace Carbon.h by coreFoundation.h, fix build with x11 enable on mac osx with --enable-macosx-bundle enable
nplourde
parents: 15145
diff changeset
12 #include <CoreFoundation/CoreFoundation.h>
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
13 #include <sys/types.h>
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
14 #include <sys/stat.h>
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
15 #include <stdio.h>
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
16 #include <stdlib.h>
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
17 #include <unistd.h>
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
18 #include <string.h>
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
19 #endif
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
20
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
21 char *get_path(char *filename){
6a74454ea121 some cleanup
arpi
parents:
diff changeset
22 char *homedir;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
23 char *buff;
10026
b8780122e043 Cygwin should behave like a Unix environment, i.e. config files should be
diego
parents: 9929
diff changeset
24 #if defined(__MINGW32__)
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
25 static char *config_dir = "/mplayer";
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
26 #else
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
27 static char *config_dir = "/.mplayer";
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
28 #endif
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
29 int len;
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
30 #ifdef MACOSX_BUNDLE
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
31 struct stat dummy;
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
32 CFIndex maxlen=256;
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
33 CFURLRef res_url_ref=NULL;
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
34 CFURLRef bdl_url_ref=NULL;
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
35 char *res_url_path = NULL;
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
36 char *bdl_url_path = NULL;
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
37 #endif
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
38
6a74454ea121 some cleanup
arpi
parents:
diff changeset
39 if ((homedir = getenv("HOME")) == NULL)
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
40 #if defined(__MINGW32__)||defined(__CYGWIN__) /*hack to get fonts etc. loaded outside of cygwin environment*/
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
41 {
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
42 int i,imax=0;
9929
faust3
parents: 9926
diff changeset
43 char exedir[260];
faust3
parents: 9926
diff changeset
44 GetModuleFileNameA(NULL, exedir, 260);
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
45 for(i=0; i< strlen(exedir);i++)if(exedir[i] =='\\'){exedir[i]='/';imax=i;}
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
46 exedir[imax]='\0';
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
47 homedir = exedir;
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
48 }
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
49 #else
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
50 return NULL;
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
51 #endif
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
52 len = strlen(homedir) + strlen(config_dir) + 1;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
53 if (filename == NULL) {
6a74454ea121 some cleanup
arpi
parents:
diff changeset
54 if ((buff = (char *) malloc(len)) == NULL)
6a74454ea121 some cleanup
arpi
parents:
diff changeset
55 return NULL;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
56 sprintf(buff, "%s%s", homedir, config_dir);
6a74454ea121 some cleanup
arpi
parents:
diff changeset
57 } else {
6a74454ea121 some cleanup
arpi
parents:
diff changeset
58 len += strlen(filename) + 1;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
59 if ((buff = (char *) malloc(len)) == NULL)
6a74454ea121 some cleanup
arpi
parents:
diff changeset
60 return NULL;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
61 sprintf(buff, "%s%s/%s", homedir, config_dir, filename);
6a74454ea121 some cleanup
arpi
parents:
diff changeset
62 }
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
63
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
64 #ifdef MACOSX_BUNDLE
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
65 if(stat(buff, &dummy)) {
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
66
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
67 res_url_ref=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
68 bdl_url_ref=CFBundleCopyBundleURL(CFBundleGetMainBundle());
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
69
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
70 if(res_url_ref&&bdl_url_ref) {
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
71
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
72 res_url_path=malloc(maxlen);
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
73 bdl_url_path=malloc(maxlen);
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
74
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
75 while(!CFURLGetFileSystemRepresentation(res_url_ref, true, res_url_path, maxlen)) {
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
76 maxlen*=2;
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
77 res_url_path=realloc(res_url_path, maxlen);
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
78 }
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
79 CFRelease(res_url_ref);
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
80
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
81 while(!CFURLGetFileSystemRepresentation(bdl_url_ref, true, bdl_url_path, maxlen)) {
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
82 maxlen*=2;
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
83 bdl_url_path=realloc(bdl_url_path, maxlen);
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
84 }
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
85 CFRelease(bdl_url_ref);
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
86
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
87 if( strcmp(res_url_path, bdl_url_path) == 0)
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
88 res_url_path = NULL;
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
89 }
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
90
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
91 if(res_url_path&&filename) {
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
92 if((strlen(filename)+strlen(res_url_path)+2)>maxlen) {
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
93 maxlen=strlen(filename)+strlen(res_url_path)+2;
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
94 }
15625
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
95 free(buff);
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
96 buff = (char *) malloc(maxlen);
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
97 strcpy(buff, res_url_path);
4be161b8e0ef compare resource url with bundle url, if its the same path do not use has conf file location.
nplourde
parents: 15237
diff changeset
98
15145
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
99 strcat(buff,"/");
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
100 strcat(buff, filename);
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
101 }
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
102 }
a7f11c8091e4 allows the Mac OS X version of MPlayer to look for its data files inside the Resources directory of the appwrapper. patch by Chris Roccati <roccati@pobox.com>
nplourde
parents: 12891
diff changeset
103 #endif
3746
d21bae2028a6 some debugging
arpi
parents: 2557
diff changeset
104 mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff);
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
105 return buff;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
106 }