MCPcopy Create free account
hub / github.com/diasurgical/devilution / BaseFile_Create

Function BaseFile_Create

3rdParty/StormLib/src/FileStream.cpp:76–114  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

74// Local functions - base file support
75
76static bool BaseFile_Create(TFileStream * pStream)
77{
78#ifdef PLATFORM_WINDOWS
79 {
80 DWORD dwWriteShare = (pStream->dwFlags & STREAM_FLAG_WRITE_SHARE) ? FILE_SHARE_WRITE : 0;
81
82 pStream->Base.File.hFile = CreateFile(pStream->szFileName,
83 GENERIC_READ | GENERIC_WRITE,
84 dwWriteShare | FILE_SHARE_READ,
85 NULL,
86 CREATE_ALWAYS,
87 0,
88 NULL);
89 if(pStream->Base.File.hFile == INVALID_HANDLE_VALUE)
90 return false;
91 }
92#endif
93
94#if defined(PLATFORM_MAC) || defined(PLATFORM_LINUX) || defined(PLATFORM_HAIKU) || defined(PLATFORM_AMIGA) || defined(PLATFORM_SWITCH)
95 {
96 intptr_t handle;
97
98 handle = open(pStream->szFileName, O_RDWR | O_CREAT | O_TRUNC | O_LARGEFILE, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
99 if(handle == -1)
100 {
101 nLastError = errno;
102 pStream->Base.File.hFile = INVALID_HANDLE_VALUE; // BUGFIX (devilutionX)
103 return false;
104 }
105
106 pStream->Base.File.hFile = (HANDLE)handle;
107 }
108#endif
109
110 // Reset the file size and position
111 pStream->Base.File.FileSize = 0;
112 pStream->Base.File.FilePos = 0;
113 return true;
114}
115
116static bool BaseFile_Open(TFileStream * pStream, const TCHAR * szFileName, DWORD dwStreamFlags)
117{

Callers 1

FileStream_CreateFileFunction · 0.85

Calls 1

openFunction · 0.50

Tested by

no test coverage detected