adding the code documentation guide lines
[mplayer/glamo.git] / get_path.c
blob0cd65297731d5734e735ff0128a04ca98bb2d4a1
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.
11 char *get_path(char *filename){
12 char *homedir;
13 char *buff;
14 #if defined(__MINGW32__)
15 static char *config_dir = "/mplayer";
16 #else
17 static char *config_dir = "/.mplayer";
18 #endif
19 int len;
21 if ((homedir = getenv("HOME")) == NULL)
22 #if defined(__MINGW32__)||defined(__CYGWIN__) /*hack to get fonts etc. loaded outside of cygwin environment*/
24 int i,imax=0;
25 char exedir[260];
26 GetModuleFileNameA(NULL, exedir, 260);
27 for(i=0; i< strlen(exedir);i++)if(exedir[i] =='\\'){exedir[i]='/';imax=i;}
28 exedir[imax]='\0';
29 homedir = exedir;
31 #else
32 return NULL;
33 #endif
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);
45 mp_msg(MSGT_GLOBAL,MSGL_V,"get_path('%s') -> '%s'\n",filename,buff);
46 return buff;