]> git.sesse.net Git - vlc/blob - src/config/dirs_macos.c
macos dirs: simplified, implemented completely and fixed warnings
[vlc] / src / config / dirs_macos.c
1 /*****************************************************************************
2  * dirs_macos.c: Mac OS X directories configuration
3  *****************************************************************************
4  * Copyright (C) 2001-2009 the VideoLAN team
5  * Copyright © 2007-2009 Rémi Denis-Courmont
6  *
7  * Authors: Gildas Bazin <gbazin@videolan.org>
8  *          Felix Paul Kühne <fkuehne at videolan dot org>
9  *
10  * This program is free software; you can redistribute it and/or modify
11  * it under the terms of the GNU General Public License as published by
12  * the Free Software Foundation; either version 2 of the License, or
13  * (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
23  *****************************************************************************/
24
25 #ifdef HAVE_CONFIG_H
26 # include "config.h"
27 #endif
28
29 #include <vlc_common.h>
30
31 #include "../libvlc.h"
32 #include <vlc_charset.h>
33 #include <vlc_configuration.h>
34
35
36 const char *config_GetConfDir( void )
37 {
38     return config_GetUserDir (VLC_CONFIG_DIR);
39 }
40
41 const char *config_GetDataDir (void)
42 {
43     return config_GetUserDir (VLC_DATA_DIR);
44 }
45
46 static char *config_GetHomeDir (void)
47 {
48     /* 1/ Try $HOME  */
49     const char *home = getenv ("HOME");
50
51     if (home == NULL)
52         home = "/tmp";
53
54     return FromLocaleDup (home);
55 }
56 /*
57 static char *config_GetAppDir (void)
58 {
59     return config_GetUserDir (VLC_CONFIG_DIR);
60 } */
61
62 char *config_GetUserDir (vlc_userdir_t type)
63 {
64     char *psz_dir;
65     const char *psz_parent = config_GetHomeDir ();
66     const char *psz_path;
67
68     switch (type)
69     {
70         case VLC_CONFIG_DIR:
71             psz_path = "%s/Library/Preferences/VLC";
72             break;
73         case VLC_TEMPLATES_DIR:
74         case VLC_DATA_DIR:
75             psz_path = "%s/Library/Application Support/VLC";
76             break;
77         case VLC_DESKTOP_DIR:
78             psz_path = "%s/Desktop";
79             break;
80         case VLC_DOWNLOAD_DIR:
81             psz_path = "%s/Downloads";
82             break;
83         case VLC_DOCUMENTS_DIR:
84             psz_path = "%s/Documents";
85             break;
86         case VLC_MUSIC_DIR:
87             psz_path = "%s/Music";
88             break;
89         case VLC_PICTURES_DIR:
90             psz_path = "%s/Pictures";
91             break;
92         case VLC_VIDEOS_DIR:
93             psz_path = "%s/Movies";
94             break;
95         case VLC_PUBLICSHARE_DIR:
96             psz_path = "%s/Public";
97             break;
98         case VLC_CACHE_DIR:
99             psz_path = "%s/Library/Caches/org.videolan.vlc";
100             break;
101         case VLC_HOME_DIR:
102         default:
103             psz_path = "%s";
104     }
105     if( asprintf( &psz_dir, psz_path, psz_parent ) == -1 )
106         psz_dir = NULL;
107     return psz_dir;
108 }