mmap_user2.c

来自「fsmlabs的real time linux的内核」· C语言 代码 · 共 42 行

C
42
字号
/* * Written by Der Herr Hofrat, der.herr@hofr.at * (C) 2002 FSMLabs * License: GPL Version 2 */#include <stdio.h>#include <unistd.h>#include <sys/mman.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include "device_common.h"int main(void){	int fd;	unsigned int *addr;	if((fd=open(SIMPLE_DEV, O_RDWR|O_SYNC))<0)	{		perror("open");		exit(-1);	}	addr = mmap(0, LEN, PROT_READ, MAP_SHARED, fd, 0);  	if(!addr)	{		perror("mmap");		exit(-1);	}	else	{		printf("Found: %s\n",addr);	}	munmap(addr,LEN);  	close(fd);	return 0;}

⌨️ 快捷键说明

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