468,315 Members | 1,418 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,315 developers. It's quick & easy.

A question about mmap() function

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?

Mar 2 '06 #1
2 5880
bite me if you can... wrote:
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
--
Artie Gold -- Austin, Texas
http://goldsays.blogspot.com
"You can't KISS* unless you MISS**"
[*-Keep it simple, stupid. **-Make it simple, stupid.]
Mar 2 '06 #2
"bite me if you can..." <cc*****@gmail.com> writes:
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.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Mar 2 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Hao Xu | last post: by
1 post views Thread by Hao Xu | last post: by
4 posts views Thread by Fabiano Sidler | last post: by
9 posts views Thread by Owen Zhang | last post: by
5 posts views Thread by Matias Surdi | last post: by
8 posts views Thread by Unknown Soldier | last post: by
2 posts views Thread by Neal Becker | last post: by
1 post views Thread by magnus.lycka | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.