OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [newlib-1.17.0/] [newlib/] [testsuite/] [newlib.elix/] [tmmap.c] - Blame information for rev 308

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 148 jeremybenn
#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
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.