MCPcopy Create free account
hub / github.com/aria2/aria2 / openFileWithFlags

Function openFileWithFlags

src/AbstractDiskWriter.cc:171–210  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

169namespace {
170#ifdef __MINGW32__
171HANDLE openFileWithFlags(const std::string& filename, int flags,
172 error_code::Value errCode)
173{
174 HANDLE hn;
175 DWORD desiredAccess = 0;
176 DWORD sharedMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
177 DWORD creationDisp = 0;
178
179 if (flags & O_RDWR) {
180 desiredAccess = GENERIC_READ | GENERIC_WRITE;
181 }
182 else if (flags & O_WRONLY) {
183 desiredAccess = GENERIC_WRITE;
184 }
185 else {
186 desiredAccess = GENERIC_READ;
187 }
188 if (flags & O_CREAT) {
189 if (flags & O_TRUNC) {
190 creationDisp |= CREATE_ALWAYS;
191 }
192 else {
193 creationDisp |= CREATE_NEW;
194 }
195 }
196 else {
197 creationDisp |= OPEN_EXISTING;
198 }
199 hn = CreateFileW(utf8ToWChar(filename).c_str(), desiredAccess, sharedMode,
200 /* lpSecurityAttributes */ 0, creationDisp,
201 FILE_ATTRIBUTE_NORMAL, /* hTemplateFile */ 0);
202 if (hn == INVALID_HANDLE_VALUE) {
203 int errNum = GetLastError();
204 throw DL_ABORT_EX3(
205 errNum,
206 fmt(EX_FILE_OPEN, filename.c_str(), fileStrerror(errNum).c_str()),
207 errCode);
208 }
209 return hn;
210}
211#else // !__MINGW32__
212int openFileWithFlags(const std::string& filename, int flags,
213 error_code::Value errCode)

Callers 2

openExistingFileMethod · 0.85
createFileMethod · 0.85

Calls 5

utf8ToWCharFunction · 0.85
fmtFunction · 0.85
fileStrerrorFunction · 0.85
safeStrerrorFunction · 0.85
make_fd_cloexecFunction · 0.85

Tested by

no test coverage detected