diff --git a/base/BUILD.gn b/base/BUILD.gn index 81edf0a5bbcc042a975b54eccef4cfe7fdc1f3fb..43928cac98093aeed25098ed10c565cca6bb7c72 100644 --- a/base/BUILD.gn +++ b/base/BUILD.gn @@ -58,6 +58,21 @@ sources_utils = [ "src/rwlock.cpp", ] +if (current_os == "mingw") { + sources_utils -= [ + "src/ashmem.cpp", + "src/datetime_ex.cpp", + "src/event_demultiplexer.cpp", + "src/event_handler.cpp", + "src/event_reactor.cpp", + "src/file_ex.cpp", + "src/semaphore_ex.cpp", + "src/thread_ex.cpp", + "src/timer.cpp", + "src/timer_event_handler.cpp", + ] +} + securec_sources = [ "src/securec/fscanf_s.c", "src/securec/fwscanf_s.c", @@ -110,7 +125,16 @@ ohos_static_library("utilsbase") { ] public_configs = [ ":static_utils_config" ] defines = [ "CONFIG_HILOG" ] - external_deps = [ "hilog_native:libhilog_base" ] + + deps = [] + + if (current_os != "mingw") { + external_deps = [ "hilog_native:libhilog_base" ] + } else { + cflags = [ "-Wno-inconsistent-dllimport" ] + + deps += [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_base" ] + } subsystem_name = "utils" part_name = "utils_base" @@ -124,14 +148,23 @@ ohos_shared_library("utils") { ":private_securec_config", ] public_configs = [ ":static_utils_config" ] - subsystem_name = "utils" defines = [ "CONFIG_HILOG" ] - external_deps = [ "hilog_native:libhilog_base" ] - part_name = "utils_base" install_images = [ "system", "updater", ] + + deps = [] + + if (current_os != "mingw") { + external_deps = [ "hilog_native:libhilog_base" ] + } else { + cflags = [ "-Wno-inconsistent-dllimport" ] + + deps += [ "//base/hiviewdfx/hilog/interfaces/native/innerkits:libhilog_base" ] + } + subsystem_name = "utils" + part_name = "utils_base" } ohos_static_library("utilsecurec") { diff --git a/base/include/flat_obj.h b/base/include/flat_obj.h index 0c7dd7cee766f434c9404cead448ff6347b3a076..73af4b99b0f9c406e7f7f64db06bea69601583fa 100644 --- a/base/include/flat_obj.h +++ b/base/include/flat_obj.h @@ -1,43 +1,69 @@ -/* - * Copyright (c) 2021 Huawei Device Co., Ltd. - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#ifndef UTILS_BASE_FLAT_OBJ_H -#define UTILS_BASE_FLAT_OBJ_H - -#include -#include - -#ifdef BINDER_IPC_32BIT - typedef __u32 binder_size_t; - typedef __u32 binder_uintptr_t; -#else - typedef __u64 binder_size_t; - typedef __u64 binder_uintptr_t; -#endif - -struct parcel_binder_object_header { - __u32 type; -}; -struct parcel_flat_binder_object { - struct parcel_binder_object_header hdr; - __u32 flags; - union { - binder_uintptr_t binder; - __u32 handle; - }; - binder_uintptr_t cookie; -}; - -#endif +/* + * Copyright (c) 2021 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef UTILS_BASE_FLAT_OBJ_H +#define UTILS_BASE_FLAT_OBJ_H + +#ifdef OS_mingw +#include +#include + +#ifdef BINDER_IPC_32BIT + typedef uint32_t binder_size_t; + typedef uint32_t binder_uintptr_t; +#else + typedef uint64_t binder_size_t; + typedef uint64_t binder_uintptr_t; +#endif + +struct parcel_binder_object_header { + uint32_t type; +}; +struct parcel_flat_binder_object { + struct parcel_binder_object_header hdr; + uint32_t flags; + union { + binder_uintptr_t binder; + uint32_t handle; + }; + binder_uintptr_t cookie; +}; +#else // !OS_mingw +#include +#include + +#ifdef BINDER_IPC_32BIT + typedef __u32 binder_size_t; + typedef __u32 binder_uintptr_t; +#else + typedef __u64 binder_size_t; + typedef __u64 binder_uintptr_t; +#endif + +struct parcel_binder_object_header { + __u32 type; +}; +struct parcel_flat_binder_object { + struct parcel_binder_object_header hdr; + __u32 flags; + union { + binder_uintptr_t binder; + __u32 handle; + }; + binder_uintptr_t cookie; +}; +#endif // OS_mingw + +#endif // UTILS_BASE_FLAT_OBJ_H diff --git a/base/src/directory_ex.cpp b/base/src/directory_ex.cpp index 80e89292cf6d76c94f85c5f7dbfdad4cb1fc8965..292f613646029c70f13f2e004d853720fac17137 100644 --- a/base/src/directory_ex.cpp +++ b/base/src/directory_ex.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include #include "directory_ex.h" #include #include @@ -23,6 +24,7 @@ using namespace std; namespace OHOS { +#ifndef OS_mingw string GetCurrentProcFullFileName() { char procFile[PATH_MAX + 1] = {0}; @@ -34,6 +36,13 @@ string GetCurrentProcFullFileName() procFile[ret] = '\0'; return string(procFile); } +#else +string GetCurrentProcFullFileName() +{ + assert("GetCurrentProcFullFileName Not Implement"); + return ""; +} +#endif string GetCurrentProcPath() { @@ -82,6 +91,7 @@ string IncludeTrailingPathDelimiter(const std::string& path) return path; } +#ifndef OS_mingw void GetDirFiles(const string& path, vector& files) { string pathStringWithDelimiter; @@ -108,7 +118,14 @@ void GetDirFiles(const string& path, vector& files) } closedir(dir); } +#else +void GetDirFiles(const string& path, vector& files) +{ + assert("GetCurrentProcFullFileName Not Implement"); +} +#endif +#ifndef OS_mingw bool ForceCreateDirectory(const string& path) { string::size_type index = 0; @@ -130,7 +147,15 @@ bool ForceCreateDirectory(const string& path) return access(path.c_str(), F_OK) == 0; } +#else +bool ForceCreateDirectory(const string& path) +{ + assert("GetCurrentProcFullFileName Not Implement"); + return false; +} +#endif +#ifndef OS_mingw bool ForceRemoveDirectory(const string& path) { string subPath; @@ -173,6 +198,7 @@ bool ForceRemoveDirectory(const string& path) return ret && (access(path.c_str(), F_OK) != 0); } +#endif bool RemoveFile(const string& fileName) { @@ -220,6 +246,7 @@ bool ChangeModeFile(const string& fileName, const mode_t& mode) return ChangeMode(fileName, mode); } +#ifndef OS_mingw bool ChangeModeDirectory(const string& path, const mode_t& mode) { string subPath; @@ -262,6 +289,7 @@ bool ChangeModeDirectory(const string& path, const mode_t& mode) } return ret; } +#endif bool PathToRealPath(const string& path, string& realPath) { @@ -276,7 +304,12 @@ bool PathToRealPath(const string& path, string& realPath) } char tmpPath[PATH_MAX] = {0}; - if (realpath(path.c_str(), tmpPath) == nullptr) { +#ifdef OS_mingw + auto ret = _fullpath(tmpPath, path.c_str(), sizeof(tmpPath)); +#else + auto ret = realpath(path.c_str(), tmpPath); +#endif + if (ret == nullptr) { UTILS_LOGE("path to realpath error"); return false; }