Ai
4 Star 5 Fork 67

OpenHarmony/kernel_linux_common_modules
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
check_nip_enable.c 1.22 KB
一键复制 编辑 原始数据 按行查看 历史
liangbotong 提交于 2025-01-14 11:12 +08:00 . Clean code warnings for NewIP
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2022 Huawei Device Co., Ltd.
*
* Description: check NewIP enable.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#define NIP_DISABLE_PATH ("/sys/module/newip/parameters/disable")
#define NIP_DISABLE_LENTH (5)
#define NIP_ENABLE_INVALID (0xFF)
int g_nip_enable = NIP_ENABLE_INVALID;
static void _check_nip_enable(void)
{
char tmp[NIP_DISABLE_LENTH];
FILE *fn = fopen(NIP_DISABLE_PATH, "r");
if (!fn) {
printf("fail to open %s\n\n", NIP_DISABLE_PATH);
return;
}
if (fgets(tmp, NIP_DISABLE_LENTH, fn) == NULL) {
printf("fail to gets %s\n\n", NIP_DISABLE_PATH);
fclose(fn);
return;
}
if (fclose(fn) == EOF) {
printf("fclose failed\n");
return;
}
g_nip_enable = atoi(tmp) ? 0 : 1;
}
static int check_nip_enable(void)
{
if (g_nip_enable == NIP_ENABLE_INVALID) {
_check_nip_enable();
g_nip_enable = (g_nip_enable == 1 ? 1 : 0);
}
return g_nip_enable;
}
int main(int argc, char **argv)
{
int af_ninet = check_nip_enable();
if (af_ninet)
printf("Support NewIP\n\n");
else
printf("Not support NewIP\n\n");
return 0;
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/openharmony/kernel_linux_common_modules.git
git@gitee.com:openharmony/kernel_linux_common_modules.git
openharmony
kernel_linux_common_modules
kernel_linux_common_modules
master

搜索帮助