Change yboot.c to LGPL as was intended
[yaffs/.git] / utils / mmaptest.c
1
2 // mmaptest.c
3 // Used to test mmap writing (ie yaffs_writepage)
4 //
5 // Written by James McKenzie
6 //
7
8 #include <fcntl.h>
9 #include <unistd.h>
10 #include <stdio.h>
11 #include <sys/mman.h>
12 #include <string.h>
13 #include <errno.h>
14
15 int
16 main (int argc, char *argv[])
17 {
18   int fd;
19   off_t size = 0;
20   void *map;
21
22   size = 6291456;
23
24   (void) unlink ("testfile");
25
26   fd = open ("testfile", O_RDWR | O_CREAT | O_TRUNC, 0666);
27
28   if (fd < 0)
29     {
30       perror ("open");
31       return -1;
32     }
33
34   if (lseek (fd, size, SEEK_SET) != size)
35     {
36       perror ("lseek");
37       return -1;
38     }
39
40   if (write (fd, "", 1) != 1)
41     {
42       perror ("write");
43       return -1;
44     }
45
46   size++;
47
48   map = mmap (NULL, size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
49   if (map == MAP_FAILED)
50     {
51       perror ("mmap");
52       return -1;
53     }
54
55   memset (map, 1 + (*(unsigned char *) map), size);
56
57   errno = 0;
58
59   printf ("msync(map,8536,MS_SYNC) returns %d (errno=%d [%s])\n",
60           msync (map, 8536, MS_SYNC), errno, strerror (errno));
61
62   (void) munmap (map, size);
63
64   return 0;
65 }