#ifdef _WIN32 /***********************************************************************/ /* In Insert mode, just open the file for append. Otherwise */ /* create the mapping file object. The map handle can be released */ /* immediately because they will not be used anymore. */ /* If del is true in DELETE mode, then delete the whole file. */ /* Returns the file handle that can be used by caller. */ /***********************************************************************/
HANDLE CreateFileMap(PGLOBAL g, LPCSTR filename,
MEMMAP *mm, MODE mode, bool del)
{
HANDLE hFile;
HANDLE hFileMap;
DWORD access, share, disposition;
// lenH is the high-order word of the file size
mm->lenL = GetFileSize(hFile, &mm->lenH);
CloseHandle(hFileMap); // Not used anymore
} else// MODE_INSERT /*****************************************************************/ /* The starting point must be the end of file as for append. */ /*****************************************************************/
SetFilePointer(hFile, 0, NULL, FILE_END);
return hFile;
} // end of CreateFileMap
bool CloseMemMap(LPVOID memory, size_t dwSize)
{ return (memory) ? !UnmapViewOfFile(memory) : false;
} // end of CloseMemMap
#else/* UNIX */ // Code to handle Linux and Solaris #include <sys/types.h> #include <sys/mman.h> #include <unistd.h> #include <sys/stat.h> #include <fcntl.h>
/***********************************************************************/ /* In Insert mode, just open the file for append. Otherwise */ /* create the mapping file object. The map handle can be released */ /* immediately because they will not be used anymore. */ /* If del is true in DELETE mode, then delete the whole file. */ /* Returns the file handle that can be used by caller. */ /***********************************************************************/
HANDLE CreateFileMap(PGLOBAL g, LPCSTR fileName,
MEMMAP *mm, MODE mode, bool del)
{ unsignedint openMode; int protmode;
HANDLE fd;
size_t filesize; struct stat st;
// Try to open the addressed file.
fd= global_open(g, MSGID_NONE, fileName, openMode);
if (fd != INVALID_HANDLE_VALUE && mode != MODE_INSERT) { /* We must know about the size of the file. */ if (fstat(fd, &st)) {
snprintf(g->Message, sizeof(g->Message), MSG(FILE_MAP_ERROR), fileName, errno);
close(fd); return INVALID_HANDLE_VALUE;
} // endif fstat
if ((filesize = st.st_size)) // Now we are ready to load the file. If mmap() is available we try // this first. If not available or it failed we try to load it.
mm->memory = mmap(NULL, filesize, protmode, MAP_SHARED, fd, 0); else
mm->memory = 0;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.