test_scull.c

来自「一个模拟的字符驱动程序」· C语言 代码 · 共 55 行

C
55
字号
#vi test_scull.c

#include <stdio.h>

#include <sys/types.h>

#include <sys/stat.h>

#include <fcntl.h>

#include <unistd.h>

 

int

main(void)

{

 int fd, ret;

 char *buf="a scull test";

 char  readbuf[16];

 

 // write file

 fd = open("/dev/scull", O_RDWR);

 ret = write(fd, buf, strlen(buf)+1);

 close(fd);

 

 // read file

 fd = open("/dev/scull", O_RDONLY); 

 read(fd, readbuf, ret);

 printf("%s\n", readbuf); 

 close(fd);

 

 return 0;

} 

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?