c++ - 检查字符设备

标签 c++ linux linux-kernel linux-device-driver

我有字符设备/dev/nvram,我想通过程序检查它。 一个人要求检查 struct stat 结构 aganist S_ISCHR 宏的 st_mode 字段。但我不明白这些信息。有人可以帮助一些示例程序吗?

最佳答案

这个怎么样:

#include <stdio.h>
#include <sys/stat.h>

int main()
{
    struct stat st;

    if (stat("/dev/nvram", &st) != -1)
    {
        if (S_ISCHR(st.st_mode))
        {
            printf("is char device\n");
        }
    }

    return 0;
}

关于c++ - 检查字符设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9680837/

相关文章:

c++ - 如何将任何内容隐式转换为字符串?

c++ - freopen和cout创建内部错误

linux - Fedora 18 中 init 进程读取的配置文件是什么?

linux-kernel - 构建树外内核模块、depmod - 以及为什么要重新启动?

linux-kernel - 如何使用 stap -L 选项?

c++ - 对 `JNI_CreateJavaVM' linux 的 undefined reference

c++ - 静态变量与静态成员

python - Selenium 错误加载页面

linux - 多线程fork

c - 什么时候 preempt_count() & PREEMPT_ACTIVE == 0?