gui: macos: use float for rate
[vlc.git] / src / os2 / dirs.c
blob350067472c41cf1ae119c03afb817a356f69fc4e
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 *****************************************************************************/
23 #ifdef HAVE_CONFIG_H
24 # include "config.h"
25 #endif
27 #include <vlc_common.h>
29 #include "../libvlc.h"
30 #include <vlc_charset.h>
31 #include "config/configuration.h"
33 #include <assert.h>
35 static const char *config_GetRelDir( const char *dir )
37 static int prefixlen = -1;
39 if( prefixlen == -1 )
41 prefixlen = 0;
42 while( LIBDIR[ prefixlen ] && SYSDATADIR[ prefixlen ]
43 && LIBDIR[ prefixlen ] == SYSDATADIR[ prefixlen])
44 prefixlen++;
47 return dir + prefixlen;
50 static const char *config_GetBaseDir( void )
52 static CHAR basedir[ CCHMAXPATH + 4 ] = "";
54 if( basedir[ 0 ] == '\0')
56 HMODULE hmod;
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, '\\');
63 *slash = '\0';
65 /* remove lib dir name */
66 slash = strrchr( basedir, '\\');
67 if( slash == NULL )
68 abort();
69 slash[ 1 ] = '\0';
72 return 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");
88 if (path)
89 return FromLocaleDup( path );
91 return config_GetRealDir( PKGLIBDIR );
94 static char *config_GetLibExecDir(void)
96 const char *path = getenv ("VLC_LIB_PATH");
97 if (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");
111 if (path)
112 return FromLocaleDup( path );
114 return config_GetRealDir( PKGDATADIR );
117 char *config_GetSysPath(vlc_sysdir_t type, const char *filename)
119 char *dir = NULL;
121 switch (type)
123 case VLC_PKG_DATA_DIR:
124 dir = config_GetDataDir();
125 break;
126 case VLC_PKG_LIB_DIR:
127 dir = config_GetLibDir();
128 break;
129 case VLC_PKG_LIBEXEC_DIR:
130 dir = config_GetLibExecDir();
131 break;
132 case VLC_SYSDATA_DIR:
133 dir = config_GetRealDir( SYSDATADIR );
134 break;
135 case VLC_LOCALE_DIR:
136 dir = config_GetRealDir( LOCALEDIR );
137 break;
138 default:
139 vlc_assert_unreachable();
142 if (filename == NULL || unlikely(dir == NULL))
143 return dir;
145 char *path;
146 asprintf(&path, "%s/%s", dir, filename);
147 free(dir);
148 return path;
151 static char *config_GetHomeDir (void)
153 const char *home = getenv ("HOME");
154 if (home != NULL)
155 return FromLocaleDup (home);
157 return config_GetLibDir();
160 char *config_GetUserDir (vlc_userdir_t type)
162 switch (type)
164 case VLC_HOME_DIR:
165 case VLC_CONFIG_DIR:
166 case VLC_USERDATA_DIR:
167 case VLC_CACHE_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:
173 case VLC_MUSIC_DIR:
174 case VLC_PICTURES_DIR:
175 case VLC_VIDEOS_DIR:
176 break;
178 return config_GetHomeDir ();