summaryrefslogtreecommitdiff
path: root/amiga
diff options
context:
space:
mode:
authorVincent Sanders <vince@kyllikki.org>2014-06-05 12:06:47 +0100
committerVincent Sanders <vince@kyllikki.org>2014-06-05 12:06:47 +0100
commitf1c2dde13bf1ca59a466cfed2f2d2076c06b235f (patch)
tree3c8ef58913108a1b5da66dc0431127cc655851a7 /amiga
parent80bee65a71a7e85cb800e5d1d1f58525c855cb09 (diff)
downloadnetsurf-f1c2dde13bf1ca59a466cfed2f2d2076c06b235f.tar.gz
netsurf-f1c2dde13bf1ca59a466cfed2f2d2076c06b235f.tar.bz2
extend file table with mkdir all and make fs backing store use it.
enable fs backing store for RISC OS.
Diffstat (limited to 'amiga')
-rwxr-xr-xamiga/misc.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/amiga/misc.c b/amiga/misc.c
index ac9912f5b..67240006d 100755
--- a/amiga/misc.c
+++ b/amiga/misc.c
@@ -19,8 +19,10 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
#include <sys/types.h>
+#include <sys/stat.h>
#include <proto/dos.h>
#include <proto/exec.h>
@@ -362,12 +364,76 @@ static nserror amiga_basename(const char *path, char **str, size_t *size)
return NSERROR_OK;
}
+/**
+ * Ensure that all directory elements needed to store a filename exist.
+ *
+ * @param fname The filename to ensure the path to exists.
+ * @return NSERROR_OK on success or error code on failure.
+ */
+static nserror amiga_mkdir_all(const char *fname)
+{
+ char *dname;
+ char *sep;
+ struct stat sb;
+
+ dname = strdup(fname);
+
+ sep = strrchr(dname, '/');
+ if (sep == NULL) {
+ /* no directory separator path is just filename so its ok */
+ free(dname);
+ return NSERROR_OK;
+ }
+
+ *sep = 0; /* null terminate directory path */
+
+ if (stat(dname, &sb) == 0) {
+ free(dname);
+ if (S_ISDIR(sb.st_mode)) {
+ /* path to file exists and is a directory */
+ return NSERROR_OK;
+ }
+ return NSERROR_NOT_DIRECTORY;
+ }
+ *sep = '/'; /* restore separator */
+
+ sep = dname;
+ while (*sep == '/') {
+ sep++;
+ }
+ while ((sep = strchr(sep, '/')) != NULL) {
+ *sep = 0;
+ if (stat(dname, &sb) != 0) {
+ if (nsmkdir(dname, S_IRWXU) != 0) {
+ /* could not create path element */
+ free(dname);
+ return NSERROR_NOT_FOUND;
+ }
+ } else {
+ if (! S_ISDIR(sb.st_mode)) {
+ /* path element not a directory */
+ free(dname);
+ return NSERROR_NOT_DIRECTORY;
+ }
+ }
+ *sep = '/'; /* restore separator */
+ /* skip directory separators */
+ while (*sep == '/') {
+ sep++;
+ }
+ }
+
+ free(dname);
+ return NSERROR_OK;
+}
+
/* amiga file handling operations */
static struct gui_file_table file_table = {
.mkpath = amiga_vmkpath,
.basename = amiga_basename,
.nsurl_to_path = amiga_nsurl_to_path,
.path_to_nsurl = amiga_path_to_nsurl,
+ .mkdir_all = amiga_mkdir_all,
};
struct gui_file_table *amiga_file_table = &file_table;