| 17 | |
| 18 | |
| 19 | wchar* 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 | |
| 67 | void SetName(wchar *FullName,const wchar *Name,size_t MaxSize) |
no test coverage detected