From b6c1cf6de79035f58b512f4400db458c8401379a Mon Sep 17 00:00:00 2001 From: The Android Open Source Project Date: Tue, 21 Oct 2008 07:00:00 -0700 Subject: Initial Contribution --- libs/host/Directories.cpp | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 libs/host/Directories.cpp (limited to 'libs/host/Directories.cpp') 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 +#include +#include +#include + +#ifdef HAVE_MS_C_RUNTIME +#include +#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; +} -- cgit v1.1