lilypond-1.3.21
[lilypond.git] / src / windhoos-suck-suck-suck-thank-you-cygnus.cc
blobcaecb610da9877209def4265bbe5264c1000a4ab
1 //
2 // windhoos.cc
3 //
4 #ifdef _WIN32
6 #include <sys/types.h>
7 #include <sys/mman.h>
8 #include <winbase.h>
10 /*
11 HANDLE CreateFileMapping(
12 HANDLE hFile, // handle to file to map
13 LPSECURITY_ATTRIBUTES lpFileMappingAttributes, // optional security attributes
14 DWORD flProtect, // protection for mapping object
15 DWORD dwMaximumSizeHigh, // high-order 32 bits of object size
16 DWORD dwMaximumSizeLow, // low-order 32 bits of object size
17 LPCTSTR lpName // name of file-mapping object
18 );
21 LPVOID MapViewOfFile(
22 HANDLE hFileMappingObject, // file-mapping object to map into address space
23 DWORD dwDesiredAccess, // access mode
24 DWORD dwFileOffsetHigh, // high-order 32 bits of file offset
25 DWORD dwFileOffsetLow, // low-order 32 bits of file offset
26 DWORD dwNumberOfBytesToMap // number of bytes to map
27 );
30 io.h:
31 long _get_osfhandle( int filehandle );
34 // cygnus's gnu-win32-b17.1 does not have _get_osfhandle
35 // however, after some hacking, it turns out that:
37 static const int OSF_OFFSET_i = 72;
38 static const int OSF_BASE_i = -3;
39 static const int OSF_FACTOR_i = 8;
40 // let-s hope bill doesn-t change his mind any time soon :-)
42 // so that, while waiting for cygnus's mmap, we can write:
44 // #define HAVE_GET_OSFHANDLE // no we still cannot; works only with cl.exe
45 long
46 _get_osfhandle( int filedes_i )
48 return (long)( OSF_OFFSET_i + ( filedes_i + OSF_BASE_i ) * OSF_FACTOR_i );
51 #ifdef HAVE_GET_OSFHANDLE
53 #include <iostream.h>
55 caddr_t
56 mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset)
58 (void)flags;
59 (void)prot;
60 (void)addr;
61 HANDLE osf = (HANDLE)_get_osfhandle( fd );
62 HANDLE file_handle = CreateFileMapping( osf, (void*)0, PAGE_READONLY,
63 0, len, 0 );
64 return (caddr_t)MapViewOfFile( file_handle, FILE_MAP_READ, 0, offset, len );
68 int
69 munmap(caddr_t addr, size_t len)
71 (void)len;
72 return UnmapViewOfFile( addr );
75 #else // ! HAVE_GET_OSFHANDLE //
77 caddr_t
78 mmap(caddr_t addr, size_t len, int prot, int flags, int fd, off_t offset)
80 (void)flags;
81 (void)prot;
82 (void)addr;
83 (void)offset;
84 char* ch_p = new char[ len ];
85 if ( ch_p )
86 read( fd, (void*)ch_p, len );
87 return ch_p;
91 int
92 munmap(caddr_t addr, size_t len)
94 (void)len;
95 delete (char*)addr;
96 return 0;
99 #endif // !HAVE_GET_OSFHANDLE //
102 #endif // _WIN32 //