18 /* don't want to block when open()ing a fifo */
19 #if defined(O_NONBLOCK)
20 # define FIFO_NONBLOCK O_NONBLOCK
22 # define FIFO_NONBLOCK 0
25 int stream_open(stream
*f
, const buffer
*fn
) {
36 if (-1 == (fd
= open(fn
->ptr
, O_RDONLY
| O_BINARY
| FIFO_NONBLOCK
))) {
40 if (-1 == fstat(fd
, &st
)) {
45 if (0 == st
.st_size
) {
46 /* empty file doesn't need a mapping */
51 f
->start
= mmap(NULL
, st
.st_size
, PROT_READ
, MAP_SHARED
, fd
, 0);
53 if (MAP_FAILED
== f
->start
) {
54 f
->start
= malloc((size_t)st
.st_size
);
56 || st
.st_size
!= read(fd
, f
->start
, (size_t)st
.st_size
)) {
80 fh
= CreateFile(fn
->ptr
,
85 FILE_ATTRIBUTE_READONLY
,
90 if (0 != GetFileSizeEx(fh
, &fsize
)) {
100 mh
= CreateFileMapping( fh
,
103 (sizeof(off_t
) > 4) ? fsize
>> 32 : 0,
111 FORMAT_MESSAGE_ALLOCATE_BUFFER |
112 FORMAT_MESSAGE_FROM_SYSTEM,
115 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
123 p
= MapViewOfFile(mh
,
132 f
->size
= (off_t
)fsize
;
139 int stream_close(stream
*f
) {
144 munmap(f
->start
, f
->size
);
149 #elif defined(__WIN32)
150 if (f
->start
) UnmapViewOfFile(f
->start
);