/* wvWare * Copyright (C) Caolan McNamara, Dom Lachowicz, and others * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. */ #ifdef HAVE_CONFIG_H #include "config.h" #endif #if defined _WIN32 #include "winmmap.h" #include /*mmap section got from imagick sources*/ /* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + m m a p % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method mmap emulates the Unix method of the same name. % % The format of the mmap method is: % % MagickExport void *mmap(char *address,size_t length,int protection, % int access,int file,gsf_off_t offset) % % */ void *mmap(char *address,size_t length,int protection,int access, int file,gsf_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: % % o status: Method munmap returns 0 on success; otherwise, it % returns -1 and sets errno to indicate the error. % % o map: The address of the binary large object. % % o length: The length of the binary large object. % % */ int munmap(void *map,size_t length) { if (!UnmapViewOfFile(map)) return(-1); return(0); } #else typedef int elegant; #endif