17 /* don't want to block when open()ing a fifo */
18 #if defined(O_NONBLOCK)
19 # define FIFO_NONBLOCK O_NONBLOCK
21 # define FIFO_NONBLOCK 0
24 int stream_open(stream
*f
, buffer
*fn
) {
34 if (-1 == (fd
= open(fn
->ptr
, O_RDONLY
| O_BINARY
| FIFO_NONBLOCK
))) {
38 if (-1 == fstat(fd
, &st
)) {
43 if (0 == st
.st_size
) {
44 /* empty file doesn't need a mapping */
49 f
->start
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_SHARED
, fd
, 0);
53 if (MAP_FAILED
== f
->start
) {
70 fh
= CreateFile(fn
->ptr
,
75 FILE_ATTRIBUTE_READONLY
,
80 if (0 != GetFileSizeEx(fh
, &fsize
)) {
90 mh
= CreateFileMapping( fh
,
93 (sizeof(off_t
) > 4) ? fsize
>> 32 : 0,
101 FORMAT_MESSAGE_ALLOCATE_BUFFER |
102 FORMAT_MESSAGE_FROM_SYSTEM,
105 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
113 p
= MapViewOfFile(mh
,
122 f
->size
= (off_t
)fsize
;
126 # error no mmap found
131 int stream_close(stream
*f
) {
133 if (f
->start
) munmap(f
->start
, f
->size
);
134 #elif defined(__WIN32)
135 if (f
->start
) UnmapViewOfFile(f
->start
);