C programming question

Peter L. Peres plp-ysDPMY98cNQDDBjDh4tngg at public.gmane.org
Wed Dec 24 08:47:45 UTC 2003


> I tried to read the man mmap(2) pages, but as always, these pages leave me in
> the dark. It would be so nice, if there would be a typical usage example
> included ( in all man pages!).
> These pages are designed for people who already know all the In's and outs,
> but are rather useless to anyone not yet familiar with their content.
> Am I alone in this assessment?

Ah, you came to my old conclusion that u*ix consists of four-letter
commands with 100-page apologies ;-)

Yes, you are right, up to a point. The manpages do not intend to tech you
anything, they remind the programmer of all the details. For learning, use
a book about programming or tutorials.

Wrt mmap:

#define SOMESIZE 1024

	void *p;

	fd = open("file", O_RDONLY);
	p = mmap(NULL, (size_t)SOMESIZE, PROT_READ|PROT_WRITE,
		MAP_PRIVATE, (off_t) 1000);

This maps 1024 bytes of "file", from offset 1000 in the file onwards, into
a buffer of size 1024, which mmap allocates for you and returns in p. Any
changes you make must be commited using a write() on fd (after reopening
it O_RDWR).

Peter

--
The Toronto Linux Users Group.      Meetings: http://tlug.ss.org
TLUG requests: Linux topics, No HTML, wrap text below 80 columns
How to UNSUBSCRIBE: http://tlug.ss.org/subscribe.shtml





More information about the Legacy mailing list