MCPcopy Create free account
hub / github.com/abbeycode/UnrarKit / Create

Method Create

Libraries/unrar/file.cpp:172–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

170
171
172bool File::Create(const wchar *Name,uint Mode)
173{
174 // OpenIndiana based NAS and CIFS shares fail to set the file time if file
175 // was created in read+write mode and some data was written and not flushed
176 // before SetFileTime call. So we should use the write only mode if we plan
177 // SetFileTime call and do not need to read from file.
178 bool WriteMode=(Mode & FMF_WRITE)!=0;
179 bool ShareRead=(Mode & FMF_SHAREREAD)!=0 || File::OpenShared;
180#ifdef _WIN_ALL
181 CreateMode=Mode;
182 uint Access=WriteMode ? GENERIC_WRITE:GENERIC_READ|GENERIC_WRITE;
183 DWORD ShareMode=ShareRead ? FILE_SHARE_READ:0;
184
185 // Windows automatically removes dots and spaces in the end of file name,
186 // So we detect such names and process them with \\?\ prefix.
187 wchar *LastChar=PointToLastChar(Name);
188 bool Special=*LastChar=='.' || *LastChar==' ';
189
190 if (Special && (Mode & FMF_STANDARDNAMES)==0)
191 hFile=FILE_BAD_HANDLE;
192 else
193 hFile=CreateFile(Name,Access,ShareMode,NULL,CREATE_ALWAYS,0,NULL);
194
195 if (hFile==FILE_BAD_HANDLE)
196 {
197 wchar LongName[NM];
198 if (GetWinLongPath(Name,LongName,ASIZE(LongName)))
199 hFile=CreateFile(LongName,Access,ShareMode,NULL,CREATE_ALWAYS,0,NULL);
200 }
201
202#else
203 char NameA[NM];
204 WideToChar(Name,NameA,ASIZE(NameA));
205#ifdef FILE_USE_OPEN
206 hFile=open(NameA,(O_CREAT|O_TRUNC) | (WriteMode ? O_WRONLY : O_RDWR),0666);
207#else
208 hFile=fopen(NameA,WriteMode ? WRITEBINARY:CREATEBINARY);
209#endif
210#endif
211 NewFile=true;
212 HandleType=FILE_HANDLENORMAL;
213 SkipClose=false;
214 wcsncpyz(FileName,Name,ASIZE(FileName));
215 return hFile!=FILE_BAD_HANDLE;
216}
217
218
219#if !defined(SFX_MODULE)

Callers 3

RestoreMethod · 0.80
FileCreateFunction · 0.80
UpdateExistingShortNameFunction · 0.80

Calls 4

PointToLastCharFunction · 0.85
GetWinLongPathFunction · 0.85
WideToCharFunction · 0.85
wcsncpyzFunction · 0.85

Tested by

no test coverage detected