summaryrefslogtreecommitdiffstats
path: root/external/boost/boost.file_iterator.sharing_win.patch
blob: b3b8bea3f3ffac8af3495e9a56ad40e8f728c3c5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
--- foo/misc/boost/boost/spirit/home/classic/iterator/impl/file_iterator.ipp.orig
+++ foo/misc/boost/boost/spirit/home/classic/iterator/impl/file_iterator.ipp
@@ -181,67 +181,28 @@ public:
     {}
 
     explicit mmap_file_iterator(std::string const& fileName)
-      : m_filesize(0), m_curChar(0)
-    {
-        HANDLE hFile = ::CreateFileA(
+      : mmap_file_iterator(::CreateFileA(
             fileName.c_str(),
             GENERIC_READ,
-            FILE_SHARE_READ,
+            FILE_SHARE_READ | FILE_SHARE_WRITE,
             NULL,
             OPEN_EXISTING,
             FILE_FLAG_SEQUENTIAL_SCAN,
             NULL
-        );
-
-        if (hFile == INVALID_HANDLE_VALUE)
-            return;
-
-        // Store the size of the file, it's used to construct
-        //  the end iterator
-        m_filesize = ::GetFileSize(hFile, NULL);
+        ))
+    {}
 
-        HANDLE hMap = ::CreateFileMapping(
-            hFile,
+    explicit mmap_file_iterator(std::wstring const& fileName)
+      : mmap_file_iterator(::CreateFileW(
+            fileName.c_str(),
+            GENERIC_READ,
+            FILE_SHARE_READ | FILE_SHARE_WRITE,
             NULL,
-            PAGE_READONLY,
-            0, 0,
+            OPEN_EXISTING,
+            FILE_FLAG_SEQUENTIAL_SCAN,
             NULL
-        );
-
-        if (hMap == NULL)
-        {
-            ::CloseHandle(hFile);
-            return;
-        }
-
-        LPVOID pMem = ::MapViewOfFile(
-            hMap,
-            FILE_MAP_READ,
-            0, 0, 0
-        );
-
-        if (pMem == NULL)
-        {
-            ::CloseHandle(hMap);
-            ::CloseHandle(hFile);
-            return;
-        }
-
-        // We hold both the file handle and the memory pointer.
-        // We can close the hMap handle now because Windows holds internally
-        //  a reference to it since there is a view mapped.
-        ::CloseHandle(hMap);
-
-        // It seems like we can close the file handle as well (because
-        //  a reference is hold by the filemap object).
-        ::CloseHandle(hFile);
-
-        // Store the handles inside the shared_ptr (with the custom destructors)
-        m_mem.reset(static_cast<CharT*>(pMem), ::UnmapViewOfFile);
-
-        // Start of the file
-        m_curChar = m_mem.get();
-    }
+        ))
+    {}
 
     mmap_file_iterator(const mmap_file_iterator& iter)
     { *this = iter; }
@@ -290,6 +251,59 @@ private:
     boost::shared_ptr<CharT> m_mem;
     std::size_t m_filesize;
     CharT* m_curChar;
+    
+    explicit mmap_file_iterator(HANDLE hFile)
+      : m_filesize(0), m_curChar(0)
+    {
+        if (hFile == INVALID_HANDLE_VALUE)
+            return;
+
+        // Store the size of the file, it's used to construct
+        //  the end iterator
+        m_filesize = ::GetFileSize(hFile, NULL);
+
+        HANDLE hMap = ::CreateFileMapping(
+            hFile,
+            NULL,
+            PAGE_READONLY,
+            0, 0,
+            NULL
+        );
+
+        if (hMap == NULL)
+        {
+            ::CloseHandle(hFile);
+            return;
+        }
+
+        LPVOID pMem = ::MapViewOfFile(
+            hMap,
+            FILE_MAP_READ,
+            0, 0, 0
+        );
+
+        if (pMem == NULL)
+        {
+            ::CloseHandle(hMap);
+            ::CloseHandle(hFile);
+            return;
+        }
+
+        // We hold both the file handle and the memory pointer.
+        // We can close the hMap handle now because Windows holds internally
+        //  a reference to it since there is a view mapped.
+        ::CloseHandle(hMap);
+
+        // It seems like we can close the file handle as well (because
+        //  a reference is hold by the filemap object).
+        ::CloseHandle(hFile);
+
+        // Store the handles inside the shared_ptr (with the custom destructors)
+        m_mem.reset(static_cast<CharT*>(pMem), ::UnmapViewOfFile);
+
+        // Start of the file
+        m_curChar = m_mem.get();
+    }
 };
 
 #endif // BOOST_SPIRIT_FILEITERATOR_WINDOWS
--- foo/misc/boost/boost/spirit/home/classic/iterator/file_iterator.hpp.orig
+++ foo/misc/boost/boost/spirit/home/classic/iterator/file_iterator.hpp
@@ -170,6 +170,12 @@ public:
     :   base_t(adapted_t(fileName))
     {}
 
+#ifdef BOOST_SPIRIT_FILEITERATOR_WINDOWS
+    file_iterator(std::wstring const& fileName)
+    :   base_t(adapted_t(fileName))
+    {}
+#endif
+
     file_iterator(const base_t& iter)
     :   base_t(iter)
     {}