📄 test.c
字号:
#include <stdio.h>#include <stdlib.h>#include <sys/types.h>#include <error.h>#include <unistd.h>#include <fcntl.h>#include <string.h>#include "hello.h"int main(int argc, char **argp){ int fd = open("/dev/my_driver", O_RDWR, 0664); if(fd < 0) { perror("open \"/dev/my_driver\" failure"); return EXIT_FAILURE; } printf("fd:%d\n",fd); int iSize = ioctl(fd, HELLO_IOGBUFFERSIZE); if(iSize == -1) { perror("ioctl:HELLO_IOGBUFFERSIZE"); } else { printf("get buffer size:%d\n", iSize); } int iSize2 = ioctl(fd, HELLO_IOGBUFFERSIZE2, &iSize); if(iSize2 == -1) { perror("ioctl:HELLO_IOGBUFFERSIZE2"); } else { printf("get buffer size:%d\n", iSize); } int iSize3 = ioctl(fd, 12345); if(iSize3 == -1) { perror("ioctl:12345"); } else { printf("get buffer size:%d\n", iSize); } char *pWriteData = "abcdefghijklmnopqrstuvwxyz123456789"; char szBuffer[1024] = {0}; int iReadBytes = 0; int iWriteBytes = write(fd, pWriteData, strlen(pWriteData)); if(iWriteBytes == strlen(pWriteData)) { printf("write data \"%s\" to \"/dev/my_driver\" success.\n"); iReadBytes = read(fd, szBuffer, strlen(pWriteData)); if(iReadBytes > 0) { printf("read data from \"/dev/my_driver\" success,data:%s.\n",szBuffer); } else { printf("read data from \"/dev/my_driver\" failure.\n"); } } else { printf("write data to \"/dev/my_driver\" failure, %d.\n",iWriteBytes); } close(fd); fd = -1; return EXIT_SUCCESS;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -