1 /*
2 Copyright (C) 2002 by Red Hat, Incorporated. All rights reserved.
3
4 Permission to use, copy, modify, and distribute this software
5 is freely granted, provided that this notice is preserved.
6 */
7 #include <sys/types.h>
8 #include <sys/mman.h>
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <fcntl.h>
13 #include "check.h"
14
main()15 int main()
16 {
17 int fd;
18 char *x;
19 FILE *fp;
20 char buf[40];
21
22 fd = open("my.file", O_CREAT | O_TRUNC | O_RDWR, 0644);
23
24 CHECK (fd != -1);
25
26 CHECK (write (fd, "abcdefgh", 8) == 8);
27
28 x = (char *)mmap (0, 20, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
29
30 CHECK (x != MAP_FAILED);
31
32 x[3] = 'j';
33
34 CHECK (munmap (x, 20) == 0);
35
36 CHECK (close(fd) != -1);
37
38 fp = fopen("my.file","r");
39
40 CHECK (fp != NULL);
41
42 CHECK (fread(buf, 1, 20, fp) == 8);
43
44 CHECK (strncmp (buf, "abcjefgh", 8) == 0);
45
46 exit (0);
47 }
48
49