1 /* 2 * Copyright (C) 2023 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 #ifndef DHCP_C_UTILS_H 16 #define DHCP_C_UTILS_H 17 18 #include <string> 19 #include <vector> 20 #include "kits/c/dhcp_error_code.h" 21 #include "dhcp_errcode.h" 22 #include "dhcp_logger.h" 23 24 namespace OHOS { 25 namespace DHCP { 26 #ifndef NO_SANITIZE 27 #ifdef __has_attribute 28 #if __has_attribute(no_sanitize) 29 #define NO_SANITIZE(type) __attribute__((no_sanitize(type))) 30 #endif 31 #endif 32 #endif 33 34 #ifndef NO_SANITIZE 35 #define NO_SANITIZE(type) 36 #endif 37 38 #ifndef CHECK_PTR_RETURN 39 #define CHECK_PTR_RETURN(ptr, retValue) \ 40 if ((ptr) == nullptr) { \ 41 DHCP_LOGE("Error: the ptr is null!"); \ 42 return retValue; \ 43 } 44 #endif 45 46 #ifndef CHECK_PTR_RETURN_VOID 47 #define CHECK_PTR_RETURN_VOID(ptr) \ 48 if ((ptr) == nullptr) { \ 49 DHCP_LOGE("Error: the ptr is null!"); \ 50 return; \ 51 } 52 #endif 53 54 DhcpErrorCode GetCErrorCode(ErrCode errCode); 55 int GetCallingPid(); 56 int GetCallingUid(); 57 int GetCallingTokenId(); 58 } // namespace DHCP 59 } // namespace OHOS 60 #endif 61