1/** 2 * Copyright (c) 2021-2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16#include "os/filesystem.h" 17 18#include <ostream> 19#include <string> 20#if defined PANDA_TARGET_MOBILE || defined PANDA_TARGET_UNIX || defined PANDA_TARGET_ARM32 || \ 21 defined PANDA_TARGET_ARM64 22#include <sys/stat.h> 23#endif 24#if defined(PANDA_TARGET_WINDOWS) 25#include <fileapi.h> 26#endif 27 28#include "utils/logger.h" 29 30namespace panda::os { 31 32void CreateDirectories(const std::string &folder_name) 33{ 34#ifdef PANDA_TARGET_MOBILE 35 constexpr auto DIR_PERMISSIONS = 0775; 36 mkdir(folder_name.c_str(), DIR_PERMISSIONS); 37#elif PANDA_TARGET_MACOS || PANDA_TARGET_OHOS 38 std::filesystem::create_directories(std::filesystem::path(folder_name)); 39#elif PANDA_TARGET_WINDOWS 40 CreateDirectory(folder_name.c_str(), NULL); 41#else 42 constexpr auto DIR_PERMISSIONS = 0775; 43 auto status = mkdir(folder_name.c_str(), DIR_PERMISSIONS); 44 if (status != 0) { 45 LOG(WARNING, COMMON) << "Failed to create directory \"" << folder_name.c_str() << "\"\n"; 46 LOG(WARNING, COMMON) << "Return status :" << status << "\n"; 47 } 48#endif 49} 50 51} // namespace panda::os 52