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

📄 write.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];		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;	while(1) {			len = read(STDIN_FILENO, receive, 1);			if(len!=1){				perror("Sorry,read error!");				return;			}			wlen += sprintf (writestr+wlen, "%c", receive[0]);			if (receive[0]=='\n') break;	}	if ( write(fd,writestr, wlen) < 0) {/*试图从终端输出所读字符*/		perror("\nSorry,write out error!\n");      return;	}else {			printf("write OK...\n");	}		close(fd);}

⌨️ 快捷键说明

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