• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /**
2  * @file cstl_public.c
3  * @copyright Copyright (c) Huawei Technologies Co., Ltd. 2021-2021. All rights reserved.
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15 
16  * @brief cstl_public 公共定义实现源码
17  * @details cstl模块公共定义源码
18  * @date 2021-05-14
19  * @version v0.1.0
20  * *******************************************************************************************
21  * @par 修改日志:
22  * <table>
23  * <tr><th>Date        <th>Version  <th>Author     <th>Description
24  * </table>
25  * *******************************************************************************************
26  */
27 
28 #include "cstl_public_inner.h"
29 
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33 
34 /**
35  * @ingroup cstl
36  */
IsMultiOverflow(size_t x,size_t y)37 __attribute__((visibility("default"))) bool IsMultiOverflow(size_t x, size_t y)
38 {
39     bool ret = false;
40 
41     if ((x > 0) && (y > 0)) {
42         ret = ((SIZE_MAX / x) < y) ? true : false;
43     }
44 
45     return ret;
46 }
47 
48 /* 加法溢出判断 */
49 /**
50  * @ingroup cstl
51  */
IsAddOverflow(size_t x,size_t y)52 __attribute__((visibility("default"))) bool IsAddOverflow(size_t x, size_t y)
53 {
54     return ((x + y) < x);
55 }
56 
57 /**
58  * @ingroup cstl
59  */
CstlIntCmpFunc(uintptr_t data1,uintptr_t data2)60 __attribute__((visibility("default"))) int32_t CstlIntCmpFunc(uintptr_t data1, uintptr_t data2)
61 {
62     int32_t ret;
63     uintptr_t key1Value = data1;
64     uintptr_t key2Value = data2;
65 
66     if (key1Value > key2Value) {
67         ret = 1;
68     } else if (key1Value < key2Value) {
69         ret = -1;
70     } else {
71         ret = 0;
72     }
73 
74     return ret;
75 }
76 
77 #ifdef __cplusplus
78 }
79 #endif
80