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

Function ConvertPath

Libraries/unrar/pathfn.cpp:19–64  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

17
18
19wchar* ConvertPath(const wchar *SrcPath,wchar *DestPath,size_t DestSize)
20{
21 const wchar *DestPtr=SrcPath;
22
23 // Prevent \..\ in any part of path string.
24 for (const wchar *s=DestPtr;*s!=0;s++)
25 if (IsPathDiv(s[0]) && s[1]=='.' && s[2]=='.' && IsPathDiv(s[3]))
26 DestPtr=s+4;
27
28 // Remove any amount of <d>:\ and any sequence of . and \ in the beginning of path string.
29 while (*DestPtr!=0)
30 {
31 const wchar *s=DestPtr;
32 if (s[0]!=0 && IsDriveDiv(s[1]))
33 s+=2;
34 if (s[0]=='\\' && s[1]=='\\')
35 {
36 const wchar *Slash=wcschr(s+2,'\\');
37 if (Slash!=NULL && (Slash=wcschr(Slash+1,'\\'))!=NULL)
38 s=Slash+1;
39 }
40 for (const wchar *t=s;*t!=0;t++)
41 if (IsPathDiv(*t))
42 s=t+1;
43 else
44 if (*t!='.')
45 break;
46 if (s==DestPtr)
47 break;
48 DestPtr=s;
49 }
50
51 // Code above does not remove last "..", doing here.
52 if (DestPtr[0]=='.' && DestPtr[1]=='.' && DestPtr[2]==0)
53 DestPtr+=2;
54
55 if (DestPath!=NULL)
56 {
57 // SrcPath and DestPath can point to same memory area,
58 // so we use the temporary buffer for copying.
59 wchar TmpStr[NM];
60 wcsncpyz(TmpStr,DestPtr,ASIZE(TmpStr));
61 wcsncpyz(DestPath,TmpStr,DestSize);
62 }
63 return (wchar *)DestPtr;
64}
65
66
67void SetName(wchar *FullName,const wchar *Name,size_t MaxSize)

Callers 3

CheckArgsMethod · 0.85
ExtractStreams20Function · 0.85
ExtractCurrentFileMethod · 0.85

Calls 3

IsPathDivFunction · 0.85
IsDriveDivFunction · 0.85
wcsncpyzFunction · 0.85

Tested by

no test coverage detected