• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021 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 <stdbool.h>
17 #include <stdio.h>
18 #include <string.h>
19 #include <errno.h>
20 
21 #include "init_param.h"
22 #include "beget_ext.h"
23 #include "securec.h"
24 #include "systemcapability.h"
25 
26 #define SYSCAP_MAX_SIZE 100
27 #define SYSCAP_PREFIX_NAME "SystemCapability"
28 #define CONST_SYSCAP_PREFIX_NAME "const.SystemCapability"
29 
HasSystemCapability(const char * cap)30 bool HasSystemCapability(const char *cap)
31 {
32     char capName[SYSCAP_MAX_SIZE] = { 0 };
33     char paramValue[PARAM_VALUE_LEN_MAX] = { 0 };
34     unsigned int valueLen = PARAM_VALUE_LEN_MAX;
35 
36     if (cap == NULL) {
37         BEGET_LOGE("cap input is null.");
38         return false;
39     }
40 
41     if (strncmp(SYSCAP_PREFIX_NAME, cap, sizeof(SYSCAP_PREFIX_NAME) - 1) == 0) {
42         if (snprintf_s(capName, SYSCAP_MAX_SIZE, SYSCAP_MAX_SIZE - 1, "const.%s", cap) == -1) {
43             BEGET_LOGE("Failed snprintf_s err=%d", errno);
44             return false;
45         }
46     } else if (snprintf_s(capName, SYSCAP_MAX_SIZE, SYSCAP_MAX_SIZE - 1, CONST_SYSCAP_PREFIX_NAME".%s", cap) == -1) {
47         BEGET_LOGE("Failed snprintf_s err=%d", errno);
48         return false;
49     }
50 
51     if (SystemGetParameter(capName, paramValue, &valueLen) != 0) {
52         BEGET_LOGE("Failed get paramName.");
53         return false;
54     }
55 
56     return true;
57 }