| 779 | } |
| 780 | |
| 781 | bool File::createPath(const std::string& path) { |
| 782 | if (path.empty()) { |
| 783 | return false; |
| 784 | } |
| 785 | if (base::utils::File::pathExists(path.c_str())) { |
| 786 | return true; |
| 787 | } |
| 788 | int status = -1; |
| 789 | |
| 790 | char* currPath = const_cast<char*>(path.c_str()); |
| 791 | std::string builtPath = std::string(); |
| 792 | #if ELPP_OS_UNIX |
| 793 | if (path[0] == '/') { |
| 794 | builtPath = "/"; |
| 795 | } |
| 796 | currPath = STRTOK(currPath, base::consts::kFilePathSeparator, 0); |
| 797 | #elif ELPP_OS_WINDOWS |
| 798 | // Use secure functions API |
| 799 | char* nextTok_ = nullptr; |
| 800 | currPath = STRTOK(currPath, base::consts::kFilePathSeparator, &nextTok_); |
| 801 | ELPP_UNUSED(nextTok_); |
| 802 | #endif // ELPP_OS_UNIX |
| 803 | while (currPath != nullptr) { |
| 804 | builtPath.append(currPath); |
| 805 | builtPath.append(base::consts::kFilePathSeparator); |
| 806 | #if ELPP_OS_UNIX |
| 807 | status = mkdir(builtPath.c_str(), ELPP_LOG_PERMS); |
| 808 | currPath = STRTOK(nullptr, base::consts::kFilePathSeparator, 0); |
| 809 | #elif ELPP_OS_WINDOWS |
| 810 | status = _mkdir(builtPath.c_str()); |
| 811 | currPath = STRTOK(nullptr, base::consts::kFilePathSeparator, &nextTok_); |
| 812 | #endif // ELPP_OS_UNIX |
| 813 | } |
| 814 | if (status == -1) { |
| 815 | ELPP_INTERNAL_ERROR("Error while creating path [" << path << "]", true); |
| 816 | return false; |
| 817 | } |
| 818 | return true; |
| 819 | } |
| 820 | |
| 821 | std::string File::extractPathFromFilename(const std::string& fullPath, const char* separator) { |
| 822 | if ((fullPath == "") || (fullPath.find(separator) == std::string::npos)) { |