save/open support in ios
This commit is contained in:
parent
444047fdce
commit
5a1eca115f
2 changed files with 36 additions and 13 deletions
29
src/ios.c
29
src/ios.c
|
|
@ -19,9 +19,10 @@
|
||||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
(See COPYING.txt)
|
(See COPYING.txt)
|
||||||
*/
|
*/
|
||||||
#include <stdio.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <libgen.h>
|
||||||
|
#include <limits.h>
|
||||||
#include "ios.h"
|
#include "ios.h"
|
||||||
|
|
||||||
#define IOS_FONTS_PATH "../Library/Fonts"
|
#define IOS_FONTS_PATH "../Library/Fonts"
|
||||||
|
|
@ -29,6 +30,19 @@
|
||||||
#define IOS_PICTURES_PATH "../Documents"
|
#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)
|
const char *apple_fontsPath(void)
|
||||||
{
|
{
|
||||||
return IOS_FONTS_PATH;
|
return IOS_FONTS_PATH;
|
||||||
|
|
@ -37,13 +51,22 @@ const char *apple_fontsPath(void)
|
||||||
|
|
||||||
const char *apple_preferencesPath(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;
|
return IOS_PREFERENCES_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const char *apple_globalPreferencesPath(void)
|
const char *apple_globalPreferencesPath(void)
|
||||||
{
|
{
|
||||||
return IOS_PREFERENCES_PATH;
|
return apple_preferencesPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
20
src/macos.c
20
src/macos.c
|
|
@ -36,9 +36,9 @@ const char *apple_fontsPath(void)
|
||||||
|
|
||||||
if(!p) {
|
if(!p) {
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
|
|
||||||
p = malloc(strlen(home) + strlen(MACOS_FONTS_PATH) + 1);
|
p = malloc(strlen(home) + strlen(MACOS_FONTS_PATH) + 1);
|
||||||
|
|
||||||
if(p) sprintf(p, MACOS_FONTS_PATH, getenv("HOME"));
|
if(p) sprintf(p, MACOS_FONTS_PATH, getenv("HOME"));
|
||||||
else perror("apple_fontsPath");
|
else perror("apple_fontsPath");
|
||||||
}
|
}
|
||||||
|
|
@ -50,16 +50,16 @@ const char *apple_fontsPath(void)
|
||||||
const char *apple_preferencesPath(void)
|
const char *apple_preferencesPath(void)
|
||||||
{
|
{
|
||||||
static char *p = NULL;
|
static char *p = NULL;
|
||||||
|
|
||||||
if(!p) {
|
if(!p) {
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
|
|
||||||
p = malloc(strlen(home) + strlen(MACOS_PREFERENCES_PATH) + 1);
|
p = malloc(strlen(home) + strlen(MACOS_PREFERENCES_PATH) + 1);
|
||||||
|
|
||||||
if(p) sprintf(p, MACOS_PREFERENCES_PATH, getenv("HOME"));
|
if(p) sprintf(p, MACOS_PREFERENCES_PATH, getenv("HOME"));
|
||||||
else perror("apple_preferencesPath");
|
else perror("apple_preferencesPath");
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,15 +73,15 @@ const char *apple_globalPreferencesPath(void)
|
||||||
const char *apple_picturesPath(void)
|
const char *apple_picturesPath(void)
|
||||||
{
|
{
|
||||||
static char *p = NULL;
|
static char *p = NULL;
|
||||||
|
|
||||||
if(!p) {
|
if(!p) {
|
||||||
const char *home = getenv("HOME");
|
const char *home = getenv("HOME");
|
||||||
|
|
||||||
p = malloc(strlen(home) + strlen(MACOS_PICTURES_PATH) + 1);
|
p = malloc(strlen(home) + strlen(MACOS_PICTURES_PATH) + 1);
|
||||||
|
|
||||||
if(p) sprintf(p, MACOS_PICTURES_PATH, getenv("HOME"));
|
if(p) sprintf(p, MACOS_PICTURES_PATH, getenv("HOME"));
|
||||||
else perror("apple_picturesPath");
|
else perror("apple_picturesPath");
|
||||||
}
|
}
|
||||||
|
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue