20 #include <sys/types.h>
43 if((fd = _open(name,(writefile) ? O_RDWR : O_RDONLY)) == -1)
45 fprintf(stderr,
"fileOpen: Cannot open \"%s\"",name);
48 if(fstat(fd,&buf) == -1)
50 fprintf(stderr,
"file \"%s\": fstat(fd = %d) failed",name,fd);
53 *textlen = (
Uint) buf.st_size;
71 *hndl = CreateFileMapping (
72 (HANDLE)_get_osfhandle(fd),
74 (writemap ? PAGE_READWRITE : PAGE_READONLY),
80 fprintf(stderr,
"fileParts(fd = %d, left = %ld, len = %ld, %s) failed",fd,
81 (
long) offset, (
long) len, writemap ?
"writable map" :
"readable map");
84 ret = (
void *)MapViewOfFile (
86 (writemap ? FILE_MAP_WRITE : FILE_MAP_READ),
91 fprintf(stderr,
"fileParts(fd = %d, left = %ld, len = %ld, %s) failed",fd,
92 (
long) offset, (
long) len, writemap ?
"writable map" :
"readable map");
111 fd =
fileOpen(name, textlen, writefile);
116 return fileParts(fd, 0, *textlen, hndl, writemap);
125 if (!(UnmapViewOfFile(text))) {
126 fprintf(stderr,
"Unable to unmap file");
128 if (!CloseHandle(hndl)) {
129 fprintf(stderr,
"Unable to close handle");
147 #include <sys/mman.h>
162 if((fd = open(name,(writefile) ? O_RDWR : O_RDONLY)) == -1)
164 fprintf(stderr,
"fileOpen: Cannot open \"%s\"",name);
167 if(fstat(fd,&buf) == -1)
169 fprintf(stderr,
"file \"%s\": fstat(fd = %d) failed",name,fd);
172 *textlen = (
Uint) buf.st_size;
189 addr = mmap((
void *) 0, (
size_t) len, writemap ? (PROT_READ | PROT_WRITE) : PROT_READ, MAP_PRIVATE, fd, (off_t) offset);
190 if(addr == (
void *) MAP_FAILED)
192 fprintf(stderr,
"fileParts(fd = %d, left = %ld, len = %ld, %s) failed",fd,
193 (
long) offset,(
long) len,
194 writemap ?
"writable map" :
"readable map");
212 fd =
fileOpen(name, textlen, writefile);
217 return fileParts(fd, 0, *textlen, writemap);
226 if (munmap((
void *) text, (
size_t) textlen) == -1) {
227 fprintf(stderr,
"Unable to unmap file");
Uint textlen
Length of the input text in the encoder.
static void * fileParts(int fd, Uint offset, Uint len, BOOL writemap)
Maps an open file into RAM memory.
unsigned char Uchar
Unsigned char type.
Uchar * text
Input text to the encoder.
unsigned long Uint
Unsigned int type.
#define BOOL
Boolean data type.
static void * genfile2String(char *name, Uint *textlen, BOOL writefile, BOOL writemap)
Opens a file and maps it into memory.
static int fileOpen(char *name, Uint *textlen, BOOL writefile)
Opens a file and reads gets its size.
#define False
False boolean constant.
void * file2String(char *name, Uint *textlen)
Opens a file and maps it into memory.
void freetextspace(Uchar *text, Uint textlen)
Frees the memory used by the mapping of a file.