#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
int main()
{
char * file = "test.data";
int fd = open(file, O_RDWR|O_CREAT | O_TRUNC, 00666);
if (fd < 0)
{
perror("open file error");
}
char *ptr = mmap(NULL,4,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
if (ptr == MAP_FAILED)
{
perror("mmap error");
}
ftruncate(fd,4);
//int * a = (int *)ptr; *a = 3;
*ptr = 3;
return 0;
}
#include <stdio.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/mman.h>
int main()
{
char * file = "test.data";
int fd = open(file, O_RDWR|O_CREAT | O_TRUNC, 00666);
if (fd < 0)
{
perror("open file error");
}
char *ptr = mmap(NULL,4,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0);
if (ptr == MAP_FAILED)
{
perror("mmap error");
}
ftruncate(fd,4);
//int * a = (int *)ptr; *a = 3;
*ptr = 3;
return 0;
}