1 /*****************************************************************************
2 * dirs.c: OS/2 directories configuration
3 *****************************************************************************
4 * Copyright (C) 2010 VLC authors and VideoLAN
6 * Authors: KO Myung-Hun <komh@chollian.net>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation; either version 2.1 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with this program; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
21 *****************************************************************************/
27 #include <vlc_common.h>
29 #include "../libvlc.h"
30 #include <vlc_charset.h>
31 #include "config/configuration.h"
35 static const char *config_GetRelDir( const char *dir
)
37 static int prefixlen
= -1;
42 while( LIBDIR
[ prefixlen
] && SYSDATADIR
[ prefixlen
]
43 && LIBDIR
[ prefixlen
] == SYSDATADIR
[ prefixlen
])
47 return dir
+ prefixlen
;
50 static const char *config_GetBaseDir( void )
52 static CHAR basedir
[ CCHMAXPATH
+ 4 ] = "";
54 if( basedir
[ 0 ] == '\0')
58 DosQueryModFromEIP( &hmod
, NULL
, 0, NULL
, NULL
, ( ULONG
)system_Init
);
59 DosQueryModuleName( hmod
, sizeof( basedir
), basedir
);
61 /* remove \ + the DLL name */
62 char *slash
= strrchr( basedir
, '\\');
65 /* remove lib dir name */
66 slash
= strrchr( basedir
, '\\');
75 static char *config_GetRealDir( const char *dir
)
77 char realdir
[ CCHMAXPATH
+ 4 ];
79 snprintf( realdir
, sizeof( realdir
), "%s%s",
80 config_GetBaseDir(), config_GetRelDir( dir
));
82 return FromLocaleDup( realdir
);
85 char *config_GetLibDir( void )
87 const char *path
= getenv ("VLC_LIB_PATH");
89 return FromLocaleDup( path
);
91 return config_GetRealDir( PKGLIBDIR
);
94 static char *config_GetLibExecDir(void)
96 const char *path
= getenv ("VLC_LIB_PATH");
98 return FromLocaleDup( path
);
100 return config_GetRealDir( PKGLIBEXECDIR
);
104 * Determines the shared data directory
106 * @return a nul-terminated string or NULL. Use free() to release it.
108 static char *config_GetDataDir(void)
110 const char *path
= getenv ("VLC_DATA_PATH");
112 return FromLocaleDup( path
);
114 return config_GetRealDir( PKGDATADIR
);
117 char *config_GetSysPath(vlc_sysdir_t type
, const char *filename
)
123 case VLC_PKG_DATA_DIR
:
124 dir
= config_GetDataDir();
126 case VLC_PKG_LIB_DIR
:
127 dir
= config_GetLibDir();
129 case VLC_PKG_LIBEXEC_DIR
:
130 dir
= config_GetLibExecDir();
132 case VLC_SYSDATA_DIR
:
133 dir
= config_GetRealDir( SYSDATADIR
);
136 dir
= config_GetRealDir( LOCALEDIR
);
139 vlc_assert_unreachable();
142 if (filename
== NULL
|| unlikely(dir
== NULL
))
146 asprintf(&path
, "%s/%s", dir
, filename
);
151 static char *config_GetHomeDir (void)
153 const char *home
= getenv ("HOME");
155 return FromLocaleDup (home
);
157 return config_GetLibDir();
160 char *config_GetUserDir (vlc_userdir_t type
)
166 case VLC_USERDATA_DIR
:
168 case VLC_DESKTOP_DIR
:
169 case VLC_DOWNLOAD_DIR
:
170 case VLC_TEMPLATES_DIR
:
171 case VLC_PUBLICSHARE_DIR
:
172 case VLC_DOCUMENTS_DIR
:
174 case VLC_PICTURES_DIR
:
178 return config_GetHomeDir ();