data/method/一些思考/系统移植+驱动/字符设备模板/用户空间与内核空间的信息读写/check/check.c

28 lines
522 B
C
Raw Normal View History

2024-01-29 10:44:43 +08:00
#include "stdio.h"
#include "unistd.h"
#include "sys/types.h"
#include "sys/stat.h"
#include "fcntl.h"
#include "stdlib.h"
#include "string.h"
int main(int argc, char *argv[])
{
int fd;
char buf[32];
char write_buf[] = "write_success";
char filename[32] = "/dev/test";
fd = open(filename, O_RDWR);
if(fd < 0){
printf("file %s open failed!\r\n", argv[1]);
return -1;
}
read(fd,buf,sizeof(buf));
write(fd,write_buf,sizeof(write_buf));
printf("%s\n",buf);
printf("open *******\n");
close(fd);
return 0;
}