A question about mmap() function

  • Thread starter bite me if you can...
  • Start date
B

bite me if you can...

The prototype of mmap() is:
void *
mmap(void *addr, size_t len, int prot, int flags, int fd, off_t
offset);

The second argument len is used to tell mmap() how many bytes I want to
map.
My question is: If len that i give to mmap() is larger than the size of
mapping file, and some data are wrote to these exceeding speces, where
are these data to be wrote to?

In Freebsd, this program section below will be executed without core
dump:
fd=open("mem.tmp", O_RDWR | O_CREAT | O_TRUNC | O_SHLOCK, S_IRWXU);
if(fd<0) {
printf("error at open() (errno: %d).\n", errno);
goto quit;
}
write(fd, empty, 8);
ptr=(char *)mmap((void *)NULL, 9, PROT_READ | PROT_WRITE, MAP_SHARED,
fd, 0);
if(fd==MAP_FAILED) {
printf("error at mmap() (errno: %d).\n", errno);
goto quit;
}

ptr[0]='a';
ptr[1]='b';
ptr[2]='b';
ptr[3]='a';
ptr[4]='b';
ptr[5]='b';
ptr[6]='b';
ptr[7]='b';
ptr[8]='z';
But, where is 'z' to be wrote to?
 
A

Artie Gold

bite said:
The prototype of mmap() is:
void *
mmap(void *addr, size_t len, int prot, int flags, int fd, off_t
[snip]

This question is off topic here (as mmap() is *not* part of ISO standard
C); it should be asked in...(see response to your next post)

HTH
--ag
 
K

Keith Thompson

bite me if you can... said:
The prototype of mmap() is:
void *
mmap(void *addr, size_t len, int prot, int flags, int fd, off_t
offset);

The second argument len is used to tell mmap() how many bytes I want to
map.
My question is: If len that i give to mmap() is larger than the size of
mapping file, and some data are wrote to these exceeding speces, where
are these data to be wrote to?

We don't know. mmap() is not a standard C function. It's defined by
POSIX, so try comp.unix.programmer.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,152
Members
46,697
Latest member
AugustNabo

Latest Threads

Top