blob: a34f5b7bc3ab4e6ba1e24012b01f2a0dd120cbb2 [file] [log] [blame]
The Android Open Source Project88b60792009-03-03 19:28:42 -08001#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
10using namespace android;
11using namespace std;
12
13string
14parent_dir(const string& path)
15{
16 return string(String8(path.c_str()).getPathDir().string());
17}
18
19int
20mkdirs(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}