Mercurial > mplayer.hg
annotate get_path.c @ 15572:5d738acd664c
support DVR format
author | reimar |
---|---|
date | Thu, 26 May 2005 11:23:15 +0000 |
parents | 55d9619d75e5 |
children | 4be161b8e0ef |
rev | line source |
---|---|
2557 | 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 | 21 char *get_path(char *filename){ |
22 char *homedir; | |
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 | 27 static char *config_dir = "/.mplayer"; |
9926
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
28 #endif |
2557 | 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 | 33 |
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 | 38 char exedir[260]; |
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 | 45 return NULL; |
9926
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
46 #endif |
2557 | 47 len = strlen(homedir) + strlen(config_dir) + 1; |
48 if (filename == NULL) { | |
49 if ((buff = (char *) malloc(len)) == NULL) | |
50 return NULL; | |
51 sprintf(buff, "%s%s", homedir, config_dir); | |
52 } else { | |
53 len += strlen(filename) + 1; | |
54 if ((buff = (char *) malloc(len)) == NULL) | |
55 return NULL; | |
56 sprintf(buff, "%s%s/%s", homedir, config_dir, filename); | |
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 | 90 mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff); |
2557 | 91 return buff; |
92 } |