⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 read.c

📁 一个驱动程序开发 一个系统调用 内附文档 非常详细
💻 C
字号:
#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/ioctl.h>#include <unistd.h>#include <stdio.h>#include <string.h>#include <stdlib.h>#include <signal.h>#include <time.h>#define BUFSIZE 1024*100#define MAXDATALEN (sizeof(int))struct timespec ts;int end = 0;void clean_exit(int dummy) {	end = 1;}main() {	int fd, len, wlen;	char receive[BUFSIZE];	char writestr[32*BUFSIZE];	int tmp = sizeof(char);	char tmp2;	int k, i, o;		signal(SIGTERM, clean_exit);		signal(SIGINT, clean_exit);		fd = open("/dev/mpcdevice0", O_RDWR);	if( fd == -1) {		printf("open error...\n");		exit(0);	}	wlen = 0;k=1;	while(1){		len = read(fd, receive, 1);		if (len<=0){			close(fd);			return 0;		}		wlen += sprintf (writestr+wlen, "%c", receive[0]);		if (receive[0]=='\n') break;	}	len=write(STDOUT_FILENO,writestr, wlen);	if (len>0) printf("read OK...\n");		close(fd);}

⌨️ 快捷键说明

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