1 /*****************************************************************************
2 * dirs_macos.c: MacOS directories configuration
3 *****************************************************************************
4 * Copyright (C) 2001-2007 the VideoLAN team
5 * Copyright © 2007-2009 Rémi Denis-Courmont
7 * Authors: Gildas Bazin <gbazin@videolan.org>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22 *****************************************************************************/
28 #include <vlc_common.h>
30 #include "../libvlc.h"
31 #include <vlc_charset.h>
32 #include <vlc_configuration.h>
39 const char *config_GetDataDir( void )
41 static char path[PATH_MAX] = "";
43 #warning FIXME: thread-safety!
46 snprintf( path, sizeof( path ), "%s" DIR_SEP "share", psz_vlcpath );
47 path[sizeof( path ) - 1] = '\0';
52 static const char *GetDir(void)
54 /* FIXME: a full memory page here - quite a waste... */
55 static char homedir[PATH_MAX] = "";
57 static pthread_mutex_t lock = PTHREAD_MUTEX_INITIALIZER;
58 pthread_mutex_lock (&lock);
62 const char *psz_localhome = getenv( "HOME" );
63 #if defined(HAVE_GETPWUID_R)
64 char buf[sysconf (_SC_GETPW_R_SIZE_MAX)];
65 if (psz_localhome == NULL)
67 struct passwd pw, *res;
69 if (!getpwuid_r (getuid (), &pw, buf, sizeof (buf), &res) && res)
70 psz_localhome = pw.pw_dir;
73 if (psz_localhome == NULL)
74 psz_localhome = getenv( "TMP" );
75 if (psz_localhome == NULL)
76 psz_localhome = "/tmp";
78 const char *uhomedir = FromLocale (psz_localhome);
79 strncpy (homedir, uhomedir, sizeof (homedir) - 1);
80 homedir[sizeof (homedir) - 1] = '\0';
81 LocaleFree (uhomedir);
83 pthread_mutex_unlock (&lock);
87 const char *config_GetConfDir( void )
89 static char path[PATH_MAX] = "";
91 #warning FIXME: system config is not the same as shared app data...
94 snprintf( path, sizeof( path ), "%s" DIR_SEP "share", /* FIXME: Duh? */
96 path[sizeof( path ) - 1] = '\0';
101 static char *config_GetHomeDir (void)
104 const char *home = getenv ("HOME");
105 #if defined(HAVE_GETPWUID_R)
106 /* 2/ Try /etc/passwd */
107 char buf[sysconf (_SC_GETPW_R_SIZE_MAX)];
110 struct passwd pw, *res;
112 if (!getpwuid_r (getuid (), &pw, buf, sizeof (buf), &res) && res)
116 /* 3/ Desperately try $TMP */
118 home = getenv( "TMP" );
119 /* 4/ Beyond hope, hard-code /tmp */
123 return FromLocaleDup (home);
126 static char *config_GetAppDir (void)
129 const char *psz_parent = GetDir ();
131 if( asprintf( &psz_dir, "%s/Library/Preferences/VLC", psz_parent ) == -1 )
136 char *config_GetUserDir (vlc_userdir_t type)
141 return config_GetHomeDir ();
145 return config_GetAppDir ();
147 case VLC_DESKTOP_DIR:
148 case VLC_DOWNLOAD_DIR:
149 case VLC_TEMPLATES_DIR:
150 case VLC_PUBLICSHARE_DIR:
151 case VLC_DOCUMENTS_DIR:
153 case VLC_PICTURES_DIR:
155 #warning FIXME not implemented
156 return config_GetUserDir (VLC_HOME_DIR);;