// Arthur: zhangxiao
// Data: 2014/12/24
// Note: mmap write
/*******************/
#include
#include
#include
#include
#include
#include
#include
#include
//#define FILENAME "/home/zhangxiao/embededSystem/example/Mmap/test"
#define FILENAME "/tmp/test"
#define BUFLEN 128
typedef struct
{
char name[BUFLEN];
int id;
}people;
int main(int argc, char** argv)
{
int i;
unsigned int pmap=0;
int fd;
fd=open(FILENAME ,O_CREAT|O_RDWR|O_TRUNC,00777 );
assert(fd !=-1);
pmap = (unsigned int)mmap(0,sizeof(people),PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
assert(pmap!=-1);
write(fd," ",sizeof(people)); //write something
unsigned int addr;
addr=pmap;
char tempname[30]="helloworld";
int tempid=253;
addr = pmap + sizeof(char)*BUFLEN;
memcpy((void *)pmap,tempname,strlen(tempname)+1);
memcpy((void *)addr, &tempid,sizeof(int));
munmap((void *) pmap,sizeof(char)*BUFLEN);
close(fd);
printf("umap ok\r\n");
return 0;
}