1 /*
2 ios.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 <string.h>
23 #include <sys/stat.h>
24 #include <libgen.h>
25 #include <limits.h>
26 #include "ios.h"
27
28 #define IOS_FONTS_PATH "../Library/Fonts"
29 #define IOS_PREFERENCES_PATH "../Library/Application Support/TuxPaint"
30 #define IOS_PICTURES_PATH "../Documents"
31
32
33 /* Recursively mkdir */
_mkdir_r(const char * path)34 static int _mkdir_r(const char *path)
35 {
36 const char parent[PATH_MAX];
37
38 if(!dirname_r(path, parent)) return 1; /* parent = dirname(path) */
39 if(strcmp(parent, ".") == 0) return 0; /* if(parent == ".") return */
40
41 _mkdir_r(parent); /* mkdir_r(parent) */
42 return mkdir(path, 0777); /* mkdir(path) */
43 }
44
45
apple_fontsPath(void)46 const char *apple_fontsPath(void)
47 {
48 return IOS_FONTS_PATH;
49 }
50
51
apple_preferencesPath(void)52 const char *apple_preferencesPath(void)
53 {
54 static int init = 0;
55
56 /* Ensure the preferences path exists */
57 if(!init) {
58 _mkdir_r(IOS_PREFERENCES_PATH);
59
60 init = 1;
61 }
62
63 return IOS_PREFERENCES_PATH;
64 }
65
66
apple_globalPreferencesPath(void)67 const char *apple_globalPreferencesPath(void)
68 {
69 return apple_preferencesPath();
70 }
71
72
apple_picturesPath(void)73 const char *apple_picturesPath(void)
74 {
75 return IOS_PICTURES_PATH;
76 }
77