Apache HTTPD
win32filemap.c
Go to the documentation of this file.
1/*
2 __ __ _
3 ___\ \/ /_ __ __ _| |_
4 / _ \\ /| '_ \ / _` | __|
5 | __// \| |_) | (_| | |_
6 \___/_/\_\ .__/ \__,_|\__|
7 |_| XML parser
8
9 Copyright (c) 1997-2000 Thai Open Source Software Center Ltd
10 Copyright (c) 2000 Clark Cooper <[email protected]>
11 Copyright (c) 2002 Fred L. Drake, Jr. <[email protected]>
12 Copyright (c) 2016-2022 Sebastian Pipping <[email protected]>
13 Copyright (c) 2022 Martin Ettl <[email protected]>
14 Licensed under the MIT license:
15
16 Permission is hereby granted, free of charge, to any person obtaining
17 a copy of this software and associated documentation files (the
18 "Software"), to deal in the Software without restriction, including
19 without limitation the rights to use, copy, modify, merge, publish,
20 distribute, sublicense, and/or sell copies of the Software, and to permit
21 persons to whom the Software is furnished to do so, subject to the
22 following conditions:
23
24 The above copyright notice and this permission notice shall be included
25 in all copies or substantial portions of the Software.
26
27 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
28 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
29 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
30 NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
31 DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
32 OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
33 USE OR OTHER DEALINGS IN THE SOFTWARE.
34*/
35
36#define STRICT 1
37#define WIN32_LEAN_AND_MEAN 1
38
39#ifdef XML_UNICODE_WCHAR_T
40# ifndef XML_UNICODE
41# define XML_UNICODE
42# endif
43#endif
44
45#ifdef XML_UNICODE
46# define UNICODE
47# define _UNICODE
48#endif /* XML_UNICODE */
49#include <windows.h>
50#include <stdio.h>
51#include <tchar.h>
52#include "filemap.h"
53
54static void win32perror(const TCHAR *);
55
56int
58 void (*processor)(const void *, size_t, const TCHAR *, void *arg),
59 void *arg) {
60 HANDLE f;
61 HANDLE m;
62 DWORD size;
64 void *p;
65
68 if (f == INVALID_HANDLE_VALUE) {
70 return 0;
71 }
73 if (size == (DWORD)-1) {
76 return 0;
77 }
78 if (sizeHi || (size > XML_MAX_CHUNK_LEN)) {
80 return 2; /* Cannot be passed to XML_Parse in one go */
81 }
82 /* CreateFileMapping barfs on zero length files */
83 if (size == 0) {
84 static const char c = '\0';
85 processor(&c, 0, name, arg);
87 return 1;
88 }
90 if (m == NULL) {
93 return 0;
94 }
95 p = MapViewOfFile(m, FILE_MAP_READ, 0, 0, 0);
96 if (p == NULL) {
100 return 0;
101 }
102 processor(p, size, name, arg);
104 CloseHandle(m);
105 CloseHandle(f);
106 return 1;
107}
108
109static void
111 LPVOID buf = NULL;
115 NULL)) {
116 _ftprintf(stderr, _T("%s: %s"), s, buf);
117 fflush(stderr);
118 LocalFree(buf);
119 } else
120 _ftprintf(stderr, _T("%s: unknown Windows error\n"), s);
121}
#define CloseHandle(h)
#define XML_MAX_CHUNK_LEN
Definition filemap.h:45
const unsigned char * buf
Definition util_md5.h:50
void const char * arg
Definition http_vhost.h:63
apr_file_t * f
apr_size_t size
apr_vformatter_buff_t * c
Definition apr_lib.h:175
const char * s
Definition apr_strings.h:95
const void * m
apr_pool_t * p
Definition md_event.c:32
return NULL
Definition mod_so.c:359
char * name
typedef HANDLE(WINAPI *apr_winapi_fpt_CreateToolhelp32Snapshot)(DWORD dwFlags
typedef DWORD(WINAPI *apr_winapi_fpt_GetCompressedFileSizeA)(IN LPCSTR lpFileName
static void win32perror(const TCHAR *)
int filemap(const TCHAR *name, void(*processor)(const void *, size_t, const TCHAR *, void *arg), void *arg)