summaryrefslogtreecommitdiffstats
path: root/libs/host/Directories.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'libs/host/Directories.cpp')
-rw-r--r--libs/host/Directories.cpp42
1 files changed, 42 insertions, 0 deletions
diff --git a/libs/host/Directories.cpp b/libs/host/Directories.cpp
new file mode 100644
index 0000000..a34f5b7
--- /dev/null
+++ b/libs/host/Directories.cpp
@@ -0,0 +1,42 @@
+#include <host/Directories.h>
+#include <utils/String8.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+
+#ifdef HAVE_MS_C_RUNTIME
+#include <direct.h>
+#endif
+
+using namespace android;
+using namespace std;
+
+string
+parent_dir(const string& path)
+{
+ return string(String8(path.c_str()).getPathDir().string());
+}
+
+int
+mkdirs(const char* last)
+{
+ String8 dest;
+ const char* s = last-1;
+ int err;
+ do {
+ s++;
+ if (s > last && (*s == '.' || *s == 0)) {
+ String8 part(last, s-last);
+ dest.appendPath(part);
+#ifdef HAVE_MS_C_RUNTIME
+ err = _mkdir(dest.string());
+#else
+ err = mkdir(dest.string(), S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP);
+#endif
+ if (err != 0) {
+ return err;
+ }
+ last = s+1;
+ }
+ } while (*s);
+ return 0;
+}