【问题标题】:Check Character device检查字符设备
【发布时间】:2012-03-13 08:52:57
【问题描述】:

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

【问题讨论】:

  • 阅读 stat()stat64() 系统调用的手册页。

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


【解决方案1】:

这个怎么样:

#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;
}

【讨论】:

    猜你喜欢
    • 2023-04-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多