| 101 | } |
| 102 | |
| 103 | void mkdir_parent (const std::string& path) |
| 104 | { |
| 105 | std::string::size_type slash(path.find('/', 1)); |
| 106 | while (slash != std::string::npos) { |
| 107 | std::string prefix(path.substr(0, slash)); |
| 108 | struct stat status; |
| 109 | if (stat(prefix.c_str(), &status) == 0) { |
| 110 | // already exists - make sure it's a directory |
| 111 | if (!S_ISDIR(status.st_mode)) { |
| 112 | throw System_error("mkdir_parent", prefix, ENOTDIR); |
| 113 | } |
| 114 | } else { |
| 115 | if (errno != ENOENT) { |
| 116 | throw System_error("mkdir_parent", prefix, errno); |
| 117 | } |
| 118 | // doesn't exist - mkdir it |
| 119 | if (mkdir(prefix.c_str(), 0777) == -1) { |
| 120 | throw System_error("mkdir", prefix, errno); |
| 121 | } |
| 122 | } |
| 123 | |
| 124 | slash = path.find('/', slash + 1); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | std::string our_exe_path () |
| 129 | { |
no test coverage detected