Mercurial > mplayer.hg
annotate get_path.c @ 13700:23c6d54ce38e
Index-Recovery cosmetix
author | atmos4 |
---|---|
date | Wed, 20 Oct 2004 02:13:33 +0000 |
parents | 54ea3d6e657c |
children | a7f11c8091e4 |
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 */ |
2557 | 11 char *get_path(char *filename){ |
12 char *homedir; | |
13 char *buff; | |
10026
b8780122e043
Cygwin should behave like a Unix environment, i.e. config files should be
diego
parents:
9929
diff
changeset
|
14 #if defined(__MINGW32__) |
9926
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
15 static char *config_dir = "/mplayer"; |
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
16 #else |
2557 | 17 static char *config_dir = "/.mplayer"; |
9926
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
18 #endif |
2557 | 19 int len; |
20 | |
21 if ((homedir = getenv("HOME")) == NULL) | |
9926
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
22 #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
|
23 { |
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
24 int i,imax=0; |
9929 | 25 char exedir[260]; |
26 GetModuleFileNameA(NULL, exedir, 260); | |
9926
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
27 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
|
28 exedir[imax]='\0'; |
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
29 homedir = exedir; |
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
30 } |
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
31 #else |
2557 | 32 return NULL; |
9926
ad429d617df4
allow config file loading outside of cygwin environment
faust3
parents:
3746
diff
changeset
|
33 #endif |
2557 | 34 len = strlen(homedir) + strlen(config_dir) + 1; |
35 if (filename == NULL) { | |
36 if ((buff = (char *) malloc(len)) == NULL) | |
37 return NULL; | |
38 sprintf(buff, "%s%s", homedir, config_dir); | |
39 } else { | |
40 len += strlen(filename) + 1; | |
41 if ((buff = (char *) malloc(len)) == NULL) | |
42 return NULL; | |
43 sprintf(buff, "%s%s/%s", homedir, config_dir, filename); | |
44 } | |
3746 | 45 mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff); |
2557 | 46 return buff; |
47 } |