The Android Open Source Project | 88b6079 | 2009-03-03 19:28:42 -0800 | [diff] [blame] | 1 | #include <host/Directories.h> |
| 2 | #include <utils/String8.h> |
| 3 | #include <sys/types.h> |
| 4 | #include <sys/stat.h> |
| 5 | |
| 6 | #ifdef HAVE_MS_C_RUNTIME |
| 7 | #include <direct.h> |
| 8 | #endif |
| 9 | |
| 10 | using namespace android; |
| 11 | using namespace std; |
| 12 | |
| 13 | string |
| 14 | parent_dir(const string& path) |
| 15 | { |
| 16 | return string(String8(path.c_str()).getPathDir().string()); |
| 17 | } |
| 18 | |
| 19 | int |
| 20 | mkdirs(const char* last) |
| 21 | { |
| 22 | String8 dest; |
| 23 | const char* s = last-1; |
| 24 | int err; |
| 25 | do { |
| 26 | s++; |
| 27 | if (s > last && (*s == '.' || *s == 0)) { |
| 28 | String8 part(last, s-last); |
| 29 | dest.appendPath(part); |
| 30 | #ifdef HAVE_MS_C_RUNTIME |
| 31 | err = _mkdir(dest.string()); |
| 32 | #else |
| 33 | err = mkdir(dest.string(), S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IXGRP); |
| 34 | #endif |
| 35 | if (err != 0) { |
| 36 | return err; |
| 37 | } |
| 38 | last = s+1; |
| 39 | } |
| 40 | } while (*s); |
| 41 | return 0; |
| 42 | } |