summaryrefslogtreecommitdiff
path: root/utils
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 /utils
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 'utils')
-rw-r--r--utils/file.c73
-rw-r--r--utils/file.h16
-rw-r--r--utils/filepath.c57
-rw-r--r--utils/filepath.h8
4 files changed, 89 insertions, 65 deletions
diff --git a/utils/file.c b/utils/file.c
index a2f1e94d0..14441e00e 100644
--- a/utils/file.c
+++ b/utils/file.c
@@ -23,6 +23,9 @@
#include <stdarg.h>
#include <string.h>
#include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
#include "desktop/gui_factory.h"
@@ -195,6 +198,69 @@ static nserror posix_path_to_nsurl(const char *path, struct nsurl **url_out)
}
/**
+ * 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 posix_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;
+}
+
+/**
* default to using the posix file handling
*/
static struct gui_file_table file_table = {
@@ -202,6 +268,7 @@ static struct gui_file_table file_table = {
.basename = posix_basename,
.nsurl_to_path = posix_nsurl_to_path,
.path_to_nsurl = posix_path_to_nsurl,
+ .mkdir_all = posix_mkdir_all,
};
struct gui_file_table *default_file_table = &file_table;
@@ -230,3 +297,9 @@ nserror netsurf_path_to_nsurl(const char *path, struct nsurl **url)
{
return guit->file->path_to_nsurl(path, url);
}
+
+/* exported interface documented in utils/file.h */
+nserror netsurf_mkdir_all(const char *fname)
+{
+ return guit->file->mkdir_all(fname);
+}
diff --git a/utils/file.h b/utils/file.h
index 2e47e1fa1..7baf2f019 100644
--- a/utils/file.h
+++ b/utils/file.h
@@ -106,6 +106,14 @@ struct gui_file_table {
* code on faliure.
*/
nserror (*path_to_nsurl)(const char *path, struct nsurl **url);
+
+ /**
+ * Ensure that all directory elements needed to store a filename exist.
+ *
+ * @param[in] fname The filename to ensure the path to exists.
+ * @return NSERROR_OK on success or error code on failure.
+ */
+ nserror (*mkdir_all)(const char *fname);
};
/** Default (posix) file operation table. */
@@ -156,4 +164,12 @@ nserror netsurf_nsurl_to_path(struct nsurl *url, char **path_out);
*/
nserror netsurf_path_to_nsurl(const char *path, struct nsurl **url);
+/**
+ * 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.
+ */
+nserror netsurf_mkdir_all(const char *fname);
+
#endif
diff --git a/utils/filepath.c b/utils/filepath.c
index c28a821d7..c07cc4874 100644
--- a/utils/filepath.c
+++ b/utils/filepath.c
@@ -325,60 +325,3 @@ void filepath_free_strvec(char **pathv)
free(pathv);
}
-/* exported interface documented in filepath.h */
-nserror filepath_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;
-}
diff --git a/utils/filepath.h b/utils/filepath.h
index 61b7209cc..ad077e2ce 100644
--- a/utils/filepath.h
+++ b/utils/filepath.h
@@ -127,13 +127,5 @@ char **filepath_path_to_strvec(const char *path);
void filepath_free_strvec(char **pathv);
-/**
- * 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.
- */
-nserror filepath_mkdir_all(const char *fname);
-
#endif /* _NETSURF_UTILS_FILEPATH_H_ */