1 /*
2   macos.c
3 
4   Copyright (c) 2021
5   http://www.tuxpaint.org/
6 
7   This program is free software; you can redistribute it and/or modify
8   it under the terms of the GNU General Public License as published by
9   the Free Software Foundation; either version 2 of the License, or
10   (at your option) any later version.
11 
12   This program is distributed in the hope that it will be useful,
13   but WITHOUT ANY WARRANTY; without even the implied warranty of
14   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15   GNU General Public License for more details.
16 
17   You should have received a copy of the GNU General Public License
18   along with this program; if not, write to the Free Software
19   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20   (See COPYING.txt)
21 */
22 #include <stdio.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include "macos.h"
26 
27 #define MACOS_FONTS_PATH              "%s/Library/Fonts"
28 #define MACOS_PREFERENCES_PATH        "%s/Library/Application Support/TuxPaint"
29 #define MACOS_GLOBAL_PREFERENCES_PATH "/Library/Application Support/TuxPaint"
30 #define MACOS_PICTURES_PATH           "%s/Pictures"
31 
32 
apple_fontsPath(void)33 const char *apple_fontsPath(void)
34 {
35     static char *p = NULL;
36 
37     if(!p) {
38         const char *home = getenv("HOME");
39 
40         p = malloc(strlen(home) + strlen(MACOS_FONTS_PATH) + 1);
41 
42         if(p) sprintf(p, MACOS_FONTS_PATH, getenv("HOME"));
43         else perror("apple_fontsPath");
44     }
45 
46     return p;
47 }
48 
49 
apple_preferencesPath(void)50 const char *apple_preferencesPath(void)
51 {
52     static char *p = NULL;
53 
54     if(!p) {
55         const char *home = getenv("HOME");
56 
57         p = malloc(strlen(home) + strlen(MACOS_PREFERENCES_PATH) + 1);
58 
59         if(p) sprintf(p, MACOS_PREFERENCES_PATH, getenv("HOME"));
60         else perror("apple_preferencesPath");
61     }
62 
63     return p;
64 }
65 
66 
apple_globalPreferencesPath(void)67 const char *apple_globalPreferencesPath(void)
68 {
69     return MACOS_GLOBAL_PREFERENCES_PATH;
70 }
71 
72 
apple_picturesPath(void)73 const char *apple_picturesPath(void)
74 {
75     static char *p = NULL;
76 
77     if(!p) {
78         const char *home = getenv("HOME");
79 
80         p = malloc(strlen(home) + strlen(MACOS_PICTURES_PATH) + 1);
81 
82         if(p) sprintf(p, MACOS_PICTURES_PATH, getenv("HOME"));
83         else perror("apple_picturesPath");
84     }
85 
86     return p;
87 }
88