Last change
on this file was
444,
checked in by satin@…, 6 years ago
|
add newlib,libalmos-mkh, restructure shared_syscalls.h and mini-libc
|
File size:
659 bytes
|
Line | |
---|
1 | #include <sys/types.h> |
---|
2 | #include <sys/mman.h> |
---|
3 | #include <stdio.h> |
---|
4 | #include <stdlib.h> |
---|
5 | #include <string.h> |
---|
6 | #include <fcntl.h> |
---|
7 | #include "check.h" |
---|
8 | |
---|
9 | int main() |
---|
10 | { |
---|
11 | int fd; |
---|
12 | char *x; |
---|
13 | FILE *fp; |
---|
14 | char buf[40]; |
---|
15 | |
---|
16 | fd = open("my.file", O_CREAT | O_TRUNC | O_RDWR, 0644); |
---|
17 | |
---|
18 | CHECK (fd != -1); |
---|
19 | |
---|
20 | CHECK (write (fd, "abcdefgh", 8) == 8); |
---|
21 | |
---|
22 | x = (char *)mmap (0, 20, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); |
---|
23 | |
---|
24 | CHECK (x != MAP_FAILED); |
---|
25 | |
---|
26 | x[3] = 'j'; |
---|
27 | |
---|
28 | CHECK (munmap (x, 20) == 0); |
---|
29 | |
---|
30 | CHECK (close(fd) != -1); |
---|
31 | |
---|
32 | fp = fopen("my.file","r"); |
---|
33 | |
---|
34 | CHECK (fp != NULL); |
---|
35 | |
---|
36 | CHECK (fread(buf, 1, 20, fp) == 8); |
---|
37 | |
---|
38 | CHECK (strncmp (buf, "abcjefgh", 8) == 0); |
---|
39 | |
---|
40 | exit (0); |
---|
41 | } |
---|
42 | |
---|
Note: See
TracBrowser
for help on using the repository browser.