make the mmap patch a bit nicer

This commit is contained in:
berkeviktor@aol.com 2010-08-14 05:43:34 +02:00
parent 0968466c22
commit 3d4e90367d

View File

@ -384,7 +384,7 @@ diff -ruN --strip-trailing-cr xchat-wdk.orig/src/common/ssl.c xchat-wdk/src/comm
#ifndef HAVE_SNPRINTF #ifndef HAVE_SNPRINTF
diff -ruN --strip-trailing-cr xchat-wdk.orig/src/common/text.c xchat-wdk/src/common/text.c diff -ruN --strip-trailing-cr xchat-wdk.orig/src/common/text.c xchat-wdk/src/common/text.c
--- xchat-wdk.orig/src/common/text.c 2010-05-30 04:28:04 +0200 --- xchat-wdk.orig/src/common/text.c 2010-05-30 04:28:04 +0200
+++ xchat-wdk/src/common/text.c 2010-08-14 04:31:42 +0200 +++ xchat-wdk/src/common/text.c 2010-08-14 05:41:41 +0200
@@ -19,13 +19,11 @@ @@ -19,13 +19,11 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
@ -408,14 +408,11 @@ diff -ruN --strip-trailing-cr xchat-wdk.orig/src/common/text.c xchat-wdk/src/com
if (sess->text_scrollback == SET_DEFAULT) if (sess->text_scrollback == SET_DEFAULT)
{ {
@@ -296,9 +296,32 @@ @@ -296,9 +296,33 @@
if (fstat (fh, &statbuf) < 0) if (fstat (fh, &statbuf) < 0)
return; return;
- map = mmap (NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fh, 0); +#ifdef WIN32
- if (map == MAP_FAILED)
+ /* from http://osdir.com/ml/guile-devel-gnu/2009-04/msg00008.html */
+
+ hFile = (HANDLE)_get_osfhandle(fh); + hFile = (HANDLE)_get_osfhandle(fh);
+ if (hFile == INVALID_HANDLE_VALUE) + if (hFile == INVALID_HANDLE_VALUE)
+ { + {
@ -426,10 +423,10 @@ diff -ruN --strip-trailing-cr xchat-wdk.orig/src/common/text.c xchat-wdk/src/com
+ hMapFile = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL); + hMapFile = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL);
+ if (hMapFile == INVALID_HANDLE_VALUE) + if (hMapFile == INVALID_HANDLE_VALUE)
+ { + {
return; + return;
+ } + }
+ +
+ /* Select which portions of the file we need (entire file) */ + /* Select which portions of the file we need */
+ map = (char *)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0); + map = (char *)MapViewOfFile(hMapFile, FILE_MAP_READ, 0, 0, 0);
+ +
+ if (map == NULL) + if (map == NULL)
@ -437,20 +434,25 @@ diff -ruN --strip-trailing-cr xchat-wdk.orig/src/common/text.c xchat-wdk/src/com
+ CloseHandle(hMapFile); + CloseHandle(hMapFile);
+ return; + return;
+ } + }
+ /*map = mmap (NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fh, 0); +#else
+ if (map == MAP_FAILED) map = mmap (NULL, statbuf.st_size, PROT_READ, MAP_PRIVATE, fh, 0);
+ return;*/ if (map == MAP_FAILED)
return;
+#endif
end_map = map + statbuf.st_size; end_map = map + statbuf.st_size;
@@ -349,7 +372,9 @@ @@ -349,7 +373,13 @@
/*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf, NULL, NULL, NULL, 0);*/ /*EMIT_SIGNAL (XP_TE_GENMSG, sess, "*", buf, NULL, NULL, NULL, 0);*/
} }
- munmap (map, statbuf.st_size); +#ifdef WIN32
+ /* munmap (map, statbuf.st_size); */
+ CloseHandle(hMapFile); + CloseHandle(hMapFile);
+ CloseHandle(hFile); + CloseHandle(hFile);
+#else
munmap (map, statbuf.st_size);
+#endif
+
close (fh); close (fh);
} }