I'm trying to open a file with mmap: It just works fine when using MAP_PRIVATE, but MAP_SHARED causes a invalid argument error: The file for mmap ist read/write
int size;
struct stat s;
const char * file_name = argv[1];
int fd = open (argv[1], O_RDWR);
int pagesize = sysconf(_SC_PAGE_SIZE);
/* Get the size of the file. */
int status = fstat (fd, & s);
size = s.st_size;
size += pagesize-(size%pagesize);
//mmap memory
d = mmap (0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
//error handeling
if(d == -1)
{
perror("mmap");
printf("Error opening file %s\n",argv[1]);
return -1;
}
What am I doing wrong?