lkml.org 
[lkml]   [2000]   [Jul]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
Subjectmsync bug or RTFM ??

Hi,

Based on what I've read in the man pages for
mmap/msync/munmap, and Stevens' APITUE, I think the following
program should create a file with scribbles in it. What I get
is a zero length file (on 2.2.1[46]).

Is this pointing to a bug in msync, or is there some other ;)
FM I should R ? Or maybe someone can give me a hint if I
misunderstood something I supposedly read?

TIA -- Jim

----------

#include <fcntl.h>
#include <sys/mman.h>
#include <sys/stat.h>

int main (int argc, char *argv[]) {

int fd, i = 0, flen = 500;
unsigned char *ptr, *start;

fd = open ("scribble.dat", O_RDWR | O_CREAT | O_TRUNC,
S_IRUSR|S_IWUSR|S_IRGRP|S_IROTH );
if (fd < 0) {
perror ("Couldn't open output file");
exit (-1);
}
ptr = start = mmap (0, flen, PROT_WRITE, MAP_PRIVATE, fd, 0);
if ((long)ptr == -1) {
perror ("couldn't mmap output file");
exit (-1);
}
while (i++ < flen) *ptr++ = i%256;

if (msync (start, flen, MS_SYNC)) {
perror ("Couldn't sync output file");
exit (-1);
}
if (munmap (start, flen)) {
perror ("couldn't unmap ouput file");
exit (-1);
}
if (close(fd)) {
perror ("couldn't close output file");
exit (-1);
}
exit (0);
}

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2005-03-22 13:57    [W:0.052 / U:0.104 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site