Re: cdb for Win32?
Geo Pertea <[email protected]> Thu, 09 Dec 2004 11:51:41 -0500
| Newsgroups | gmane.comp.djb.cdb |
|---|---|
| Message-ID | <[email protected]> |
It can be ported, both to cygwin and native win32.
cygwin compilation should work without any issues (not sure if any
source changes are needed at all).
For the "pure" win32 port, it's mainly about emulating unistd.h mmap and
munmap calls, I used the code below, curtesy of Imagick graphics
package developers:
--------------------------------------------------------
#ifdef __WIN32__
#include <windows.h>
/* m m a p === got it from imagick sources
% Method mmap emulates the Unix method of the same name.
% The format of the mmap method is:
% void *mmap(char *address,size_t length,int protection,
% int access,int file,off_t offset)
*/
void *mmap(char *address,size_t length,int protection,int access,
int file, off_t offset) {
void *map;
HANDLE handle;
map=(void *) NULL;
handle=INVALID_HANDLE_VALUE;
switch (protection)
{
case PROT_READ:
default:
{
handle=CreateFileMapping((HANDLE)
_get_osfhandle(file),0,PAGE_READONLY,0,
length,0);
if (!handle)
break;
map=(void *) MapViewOfFile(handle,FILE_MAP_READ,0,0,length);
CloseHandle(handle);
break;
}
case PROT_WRITE:
{
handle=CreateFileMapping((HANDLE)
_get_osfhandle(file),0,PAGE_READWRITE,0,
length,0);
if (!handle)
break;
map=(void *) MapViewOfFile(handle,FILE_MAP_WRITE,0,0,length);
CloseHandle(handle);
break;
}
case PROT_READWRITE:
{
handle=CreateFileMapping((HANDLE)
_get_osfhandle(file),0,PAGE_READWRITE,0,
length,0);
if (!handle)
break;
map=(void *) MapViewOfFile(handle,FILE_MAP_ALL_ACCESS,0,0,length);
CloseHandle(handle);
break;
}
}
if (map == (void *) NULL)
return((void *) MAP_FAILED);
return((void *) ((char *) map+offset));
}
/* =========== m u n m a p ===========================
% Method munmap emulates the Unix method with the same name.
% The format of the munmap method is:
% int munmap(void *map,size_t length)
% A description of each parameter follows:
% > status: Method munmap returns 0 on success; otherwise, it
% returns -1 and sets errno to indicate the error.
% > map: The address of the binary large object.
% > length: The length of the binary large object.
%
*/
int munmap(void *map,size_t length) {
if (!UnmapViewOfFile(map))
return(-1);
return(0);
}
#endif