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

Function MakeDir

Libraries/unrar/filefn.cpp:3–38  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1#include "rar.hpp"
2
3MKDIR_CODE MakeDir(const wchar *Name,bool SetAttr,uint Attr)
4{
5#ifdef _WIN_ALL
6 // Windows automatically removes dots and spaces in the end of directory
7 // name. So we detect such names and process them with \\?\ prefix.
8 wchar *LastChar=PointToLastChar(Name);
9 bool Special=*LastChar=='.' || *LastChar==' ';
10 BOOL RetCode=Special ? FALSE : CreateDirectory(Name,NULL);
11 if (RetCode==0 && !FileExist(Name))
12 {
13 wchar LongName[NM];
14 if (GetWinLongPath(Name,LongName,ASIZE(LongName)))
15 RetCode=CreateDirectory(LongName,NULL);
16 }
17 if (RetCode!=0) // Non-zero return code means success for CreateDirectory.
18 {
19 if (SetAttr)
20 SetFileAttr(Name,Attr);
21 return MKDIR_SUCCESS;
22 }
23 int ErrCode=GetLastError();
24 if (ErrCode==ERROR_FILE_NOT_FOUND || ErrCode==ERROR_PATH_NOT_FOUND)
25 return MKDIR_BADPATH;
26 return MKDIR_ERROR;
27#elif defined(_UNIX)
28 char NameA[NM];
29 WideToChar(Name,NameA,ASIZE(NameA));
30 mode_t uattr=SetAttr ? (mode_t)Attr:0777;
31 int ErrCode=mkdir(NameA,uattr);
32 if (ErrCode==-1)
33 return errno==ENOENT ? MKDIR_BADPATH:MKDIR_ERROR;
34 return MKDIR_SUCCESS;
35#else
36 return MKDIR_ERROR;
37#endif
38}
39
40
41bool CreatePath(const wchar *Path,bool SkipLastName)

Callers 3

CreatePathFunction · 0.85
GetAppDataPathFunction · 0.85
ExtrCreateDirMethod · 0.85

Calls 5

PointToLastCharFunction · 0.85
FileExistFunction · 0.85
GetWinLongPathFunction · 0.85
SetFileAttrFunction · 0.85
WideToCharFunction · 0.85

Tested by

no test coverage detected