save/open support in ios

This commit is contained in:
Mark Kim 2021-03-23 23:48:53 -04:00
parent 444047fdce
commit 5a1eca115f
2 changed files with 36 additions and 13 deletions

View file

@ -19,9 +19,10 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
(See COPYING.txt)
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/stat.h>
#include <libgen.h>
#include <limits.h>
#include "ios.h"
#define IOS_FONTS_PATH "../Library/Fonts"
@ -29,6 +30,19 @@
#define IOS_PICTURES_PATH "../Documents"
/* Recursively mkdir */
static int _mkdir_r(const char *path)
{
const char parent[PATH_MAX];
if(!dirname_r(path, parent)) return 1; /* parent = dirname(path) */
if(strcmp(parent, ".") == 0) return 0; /* if(parent == ".") return */
_mkdir_r(parent); /* mkdir_r(parent) */
return mkdir(path, 0777); /* mkdir(path) */
}
const char *apple_fontsPath(void)
{
return IOS_FONTS_PATH;
@ -37,13 +51,22 @@ const char *apple_fontsPath(void)
const char *apple_preferencesPath(void)
{
static int init = 0;
/* Ensure the preferences path exists */
if(!init) {
_mkdir_r(IOS_PREFERENCES_PATH);
init = 1;
}
return IOS_PREFERENCES_PATH;
}
const char *apple_globalPreferencesPath(void)
{
return IOS_PREFERENCES_PATH;
return apple_preferencesPath();
}

View file

@ -36,9 +36,9 @@ const char *apple_fontsPath(void)
if(!p) {
const char *home = getenv("HOME");
p = malloc(strlen(home) + strlen(MACOS_FONTS_PATH) + 1);
if(p) sprintf(p, MACOS_FONTS_PATH, getenv("HOME"));
else perror("apple_fontsPath");
}
@ -50,16 +50,16 @@ const char *apple_fontsPath(void)
const char *apple_preferencesPath(void)
{
static char *p = NULL;
if(!p) {
const char *home = getenv("HOME");
p = malloc(strlen(home) + strlen(MACOS_PREFERENCES_PATH) + 1);
if(p) sprintf(p, MACOS_PREFERENCES_PATH, getenv("HOME"));
else perror("apple_preferencesPath");
}
return p;
}
@ -73,15 +73,15 @@ const char *apple_globalPreferencesPath(void)
const char *apple_picturesPath(void)
{
static char *p = NULL;
if(!p) {
const char *home = getenv("HOME");
p = malloc(strlen(home) + strlen(MACOS_PICTURES_PATH) + 1);
if(p) sprintf(p, MACOS_PICTURES_PATH, getenv("HOME"));
else perror("apple_picturesPath");
}
return p;
}