1 /* Copyright (c) 1998, 1999 Thai Open Source Software Center Ltd
2 See the file COPYING for copying permission.
6 #define WIN32_LEAN_AND_MEAN 1
8 #ifdef XML_UNICODE_WCHAR_T
17 #endif /* XML_UNICODE */
23 static void win32perror(const TCHAR
*);
26 filemap(const TCHAR
*name
,
27 void (*processor
)(const void *, size_t, const TCHAR
*, void *arg
),
36 f
= CreateFile(name
, GENERIC_READ
, FILE_SHARE_READ
, NULL
, OPEN_EXISTING
,
37 FILE_FLAG_SEQUENTIAL_SCAN
, NULL
);
38 if (f
== INVALID_HANDLE_VALUE
) {
42 size
= GetFileSize(f
, &sizeHi
);
43 if (size
== (DWORD
)-1) {
48 _ftprintf(stderr
, _T("%s: bigger than 2Gb\n"), name
);
51 /* CreateFileMapping barfs on zero length files */
53 static const char c
= '\0';
54 processor(&c
, 0, name
, arg
);
58 m
= CreateFileMapping(f
, NULL
, PAGE_READONLY
, 0, 0, NULL
);
64 p
= MapViewOfFile(m
, FILE_MAP_READ
, 0, 0, 0);
71 processor(p
, size
, name
, arg
);
79 win32perror(const TCHAR
*s
)
82 if (FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER
83 | FORMAT_MESSAGE_FROM_SYSTEM
,
86 MAKELANGID(LANG_NEUTRAL
, SUBLANG_DEFAULT
),
90 _ftprintf(stderr
, _T("%s: %s"), s
, buf
);
95 _ftprintf(stderr
, _T("%s: unknown Windows error\n"), s
);