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

📄 mmcat.c

📁 基于网络编程的例子
💻 C
字号:
/* * mmcat.c - Implement the cat command using memory maps */#include <sys/types.h>#include <sys/mman.h>#include <sys/stat.h>#include <unistd.h>#include <fcntl.h>#include <stdlib.h>#include <stdio.h>void err_quit(char *msg);int main(int argc, char *argv[]){	int fdin;	char *src;	struct stat statbuf;	off_t len;	/* make sure we were called properly */	if(argc != 2) {		fprintf(stderr, "usage: mmcat {file}\n");		exit(EXIT_FAILURE);	}		/* open the input file and stdout */	if((fdin = open(argv[1], O_RDONLY)) < 0) {		err_quit("open");	}	/* need the size of the input file for mmap call */	if((fstat(fdin, &statbuf)) < 0) {		err_quit("fstat");	}	len = statbuf.st_size;	/* map the input file */	if((src = mmap(0, len, PROT_READ, MAP_SHARED, fdin, 0)) == (void *)-1) { 		err_quit("mmap");	}	/* write it out */	printf("%s", src);	/* clean up */	close(fdin);	munmap(src, len);	exit(EXIT_SUCCESS);}void err_quit(char *msg) {	perror(msg);	exit(EXIT_FAILURE);}

⌨️ 快捷键说明

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