- #include <stdio.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <sys/mman.h>
- #include <fcntl.h>
- #define DRIVER_NAME "/dev/myvcd"
- int main(int argc, char* argv[])
- {
- char read_buf[10];
- char write_buf[20];
- int file = open(DRIVER_NAME, O_RDWR);
- if (file < 0)
- {
- printf("can not open driver/n");
- return 1;
- }
- printf("write data %d/n", write(file, "hello, world", 10));
- int size = read(file, read_buf, sizeof(read_buf));
- printf("read size is:%d/n", size);
- int i = 0;
- for (; i<size; i++)
- printf("readbuf[%d] is %d/n", i, read_buf[i]);
- printf("/n");
- close(file);
- return 0;
- }
驱动程序--客户端初步
最新推荐文章于 2025-08-01 10:20:02 发布
本文介绍了一个简单的C程序实例,演示如何通过Linux设备文件进行数据的写入和读取操作。程序首先尝试打开指定的设备文件,然后向设备写入文本“hello, world”,随后从同一设备读取数据并打印到屏幕。此示例适用于理解用户空间程序如何与内核空间的设备驱动交互。
9918

被折叠的 条评论
为什么被折叠?



