File: xs_test.c

package info (click to toggle)
libunicode-japanese-perl 0.50-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,376 kB
  • sloc: ansic: 30,821; perl: 5,635; erlang: 224; makefile: 191
file content (36 lines) | stat: -rw-r--r-- 608 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36

/* $Id: xs_test.c 4494 2002-10-29 06:23:58Z hio $ */

#include "mediate.h"
#include <unistd.h>   /* memmap */
#include <sys/mman.h> /* memmap */
#include <sys/stat.h> /* stat */
#include <fcntl.h>    /* open */

#ifndef MAP_FAILED
#define MAP_FAILED ((void*)-1)
#endif

void* do_memmap(char* filepath)
{
  int fd;
  struct stat st;
  int res;
  void* ptr;
  
  fd = open(filepath,O_RDONLY|O_NONBLOCK);
  res = fstat(fd,&st);
  if( res==-1 )
  {
    st.st_size = 0;
  }
  ptr = mmap(NULL,st.st_size,PROT_READ,MAP_PRIVATE,fd,0);
  close(fd);
  return ptr;
}

void do_unmemmap(void* ptr)
{
  munmap(ptr,0);
}