Date: Thu, 27 Jul 2000 15:22:01 +0300 From: Dimitar Peikov <mitko@rila.bg> To: hackers@FreeBSD.ORG Subject: mmap syncs and file extends Message-ID: <00072715314205.05330@earth>
index | next in thread | raw e-mail
Hi, hackers,
I've try to use mmap() and resize the mapping. msync() syncronizes only the
memory that was mmapped with mmap(). How can I extend the main file? Memory is
filled correctly, but I must write extended data to file by hand.
In my examples 'x.txt' was 11 bytes (some text); Where I'm wrong?
----------
#include <unistd.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
int main() {
char *ptr;
int fd, size=20;
fd = open("x.txt", O_RDWR | O_CREAT);
ptr = mmap(0, 15, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
ptr[0] = 'D';
ptr[6] = 'D';
ptr = mremap(ptr, 10, 20, 1);
close(fd);
ptr[10] = 'Y';
ptr[12] = 'X';
printf("1%C\n", ptr[12]);
msync(ptr, size, MS_SYNC);
munmap(ptr, size);
}
----------
--
Dimitar Peikov
Programmer
"We Build e-Business"
RILA Solutions
27 Building, Acad.G.Bonchev Str.
1113 Sofia, Bulgaria
home: (+359 2) 595495
phone: (+359 2) 9797320
phone: (+359 2) 9797300
fax: (+359 2) 9733355
http://www.rila.com
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message
help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?00072715314205.05330>
