add mmap library.
parent
ad78d69f48
commit
84cd4773f4
@ -0,0 +1,19 @@
|
|||||||
|
#ifndef MMAP_H
|
||||||
|
#define MMAP_H
|
||||||
|
|
||||||
|
#include <sys/cdefs.h>
|
||||||
|
|
||||||
|
/* open file for reading, mmap whole file, close file, write length of
|
||||||
|
* map in filesize and return pointer to map. */
|
||||||
|
extern char* mmap_read(const char *filename,unsigned long* filesize) __THROW;
|
||||||
|
|
||||||
|
/* open file for writing, mmap whole file privately (copy on write),
|
||||||
|
* close file, write length of map in filesize and return pointer to
|
||||||
|
* map. */
|
||||||
|
extern int mmap_write(const char *filename,unsigned long* filesize) __THROW;
|
||||||
|
|
||||||
|
/* open file for writing, mmap whole file shared, close file, write
|
||||||
|
* length of map in filesize and return pointer to map. */
|
||||||
|
extern int mmap_shared(const char *filename,unsigned long* filesize) __THROW;
|
||||||
|
|
||||||
|
#endif
|
@ -0,0 +1,19 @@
|
|||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include "open.h"
|
||||||
|
#include "mmap.h"
|
||||||
|
|
||||||
|
extern char* mmap_private(const char* filename,unsigned long* filesize) {
|
||||||
|
int fd=open_read(filename);
|
||||||
|
char *map;
|
||||||
|
if (fd>=0) {
|
||||||
|
*filesize=lseek(fd,0,SEEK_END);
|
||||||
|
map=mmap(0,*filesize,PROT_WRITE,MAP_PRIVATE,fd,0);
|
||||||
|
if (map==(char*)-1)
|
||||||
|
map=0;
|
||||||
|
close(fd);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include "open.h"
|
||||||
|
#include "mmap.h"
|
||||||
|
|
||||||
|
extern char* mmap_read(const char* filename,unsigned long* filesize) {
|
||||||
|
int fd=open_read(filename);
|
||||||
|
char *map;
|
||||||
|
if (fd>=0) {
|
||||||
|
*filesize=lseek(fd,0,SEEK_END);
|
||||||
|
map=mmap(0,*filesize,PROT_READ,MAP_SHARED,fd,0);
|
||||||
|
if (map==(char*)-1)
|
||||||
|
map=0;
|
||||||
|
close(fd);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
@ -0,0 +1,19 @@
|
|||||||
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/mman.h>
|
||||||
|
#include "open.h"
|
||||||
|
#include "mmap.h"
|
||||||
|
|
||||||
|
extern char* mmap_private(const char* filename,unsigned long* filesize) {
|
||||||
|
int fd=open_read(filename);
|
||||||
|
char *map;
|
||||||
|
if (fd>=0) {
|
||||||
|
*filesize=lseek(fd,0,SEEK_END);
|
||||||
|
map=mmap(0,*filesize,PROT_WRITE,MAP_SHARED,fd,0);
|
||||||
|
if (map==(char*)-1)
|
||||||
|
map=0;
|
||||||
|
close(fd);
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in New Issue