annotate get_path.c @ 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>
author nplourde
date Wed, 13 Apr 2005 11:46:35 +0000
parents 54ea3d6e657c
children 55d9619d75e5
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
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
12 #include <Carbon/Carbon.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
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;
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
32 #endif
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
33
6a74454ea121 some cleanup
arpi
parents:
diff changeset
34 if ((homedir = getenv("HOME")) == NULL)
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
35 #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
36 {
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
37 int i,imax=0;
9929
faust3
parents: 9926
diff changeset
38 char exedir[260];
faust3
parents: 9926
diff changeset
39 GetModuleFileNameA(NULL, exedir, 260);
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
40 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
41 exedir[imax]='\0';
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
42 homedir = exedir;
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
43 }
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
44 #else
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
45 return NULL;
9926
ad429d617df4 allow config file loading outside of cygwin environment
faust3
parents: 3746
diff changeset
46 #endif
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
47 len = strlen(homedir) + strlen(config_dir) + 1;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
48 if (filename == NULL) {
6a74454ea121 some cleanup
arpi
parents:
diff changeset
49 if ((buff = (char *) malloc(len)) == NULL)
6a74454ea121 some cleanup
arpi
parents:
diff changeset
50 return NULL;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
51 sprintf(buff, "%s%s", homedir, config_dir);
6a74454ea121 some cleanup
arpi
parents:
diff changeset
52 } else {
6a74454ea121 some cleanup
arpi
parents:
diff changeset
53 len += strlen(filename) + 1;
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/%s", homedir, config_dir, filename);
6a74454ea121 some cleanup
arpi
parents:
diff changeset
57 }
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
58
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
59 #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
60 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
61 CFIndex maxlen=64;
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
62 CFURLRef resources=NULL;
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 free(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
65 buff=NULL;
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
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
67 resources=CFBundleCopyResourcesDirectoryURL(CFBundleGetMainBundle());
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
68 if(resources) {
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
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
70 buff=malloc(maxlen);
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
71 *buff=0;
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
72
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
73 while(!CFURLGetFileSystemRepresentation(resources, true, buff, maxlen)) {
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 maxlen*=2;
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
75 buff=realloc(buff, maxlen);
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 }
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
77 CFRelease(resources);
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 }
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
79
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
80 if(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
81 if((strlen(filename)+strlen(buff)+2)>maxlen) {
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
82 maxlen=strlen(filename)+strlen(buff)+2;
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
83 buff=realloc(buff, maxlen);
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
84 }
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
85 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
86 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
87 }
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
88 }
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 #endif
3746
d21bae2028a6 some debugging
arpi
parents: 2557
diff changeset
90 mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff);
2557
6a74454ea121 some cleanup
arpi
parents:
diff changeset
91 return buff;
6a74454ea121 some cleanup
arpi
parents:
diff changeset
92 }