Ai
4 Star 5 Fork 67

OpenHarmony/kernel_linux_common_modules
关闭

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
get_af_ninet.c 989 Bytes
一键复制 编辑 原始数据 按行查看 历史
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: get af ninet.
*
* Author: Yang Yanjun <yangyanjun@huawei.com>
*
* Data: 2022-09-06
*/
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <unistd.h>
#define AF_NINET_PATH ("/sys/module/newip/parameters/af_ninet")
#define AF_NINET_LENTH (5)
int g_af_ninet;
static void _get_af_ninet(void)
{
char tmp[AF_NINET_LENTH];
FILE *fn = fopen(AF_NINET_PATH, "r");
if (!fn) {
printf("fail to open %s\n\n", AF_NINET_PATH);
return;
}
if (fgets(tmp, AF_NINET_LENTH, fn) == NULL) {
printf("fail to gets %s\n\n", AF_NINET_PATH);
fclose(fn);
return;
}
if (fclose(fn) == EOF) {
printf("fclose failed\n");
return;
}
g_af_ninet = atoi(tmp);
}
static int get_af_ninet(void)
{
if (g_af_ninet == 0)
_get_af_ninet();
return g_af_ninet;
}
int main(int argc, char **argv)
{
printf("af_ninet=%d\n\n", get_af_ninet());
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

搜索帮助