| 83 | |
| 84 | |
| 85 | bool CharToWide(const char *Src,wchar *Dest,size_t DestSize) |
| 86 | { |
| 87 | bool RetCode=true; |
| 88 | *Dest=0; // Set 'Dest' to zero just in case the conversion will fail. |
| 89 | |
| 90 | #ifdef _WIN_ALL |
| 91 | if (MultiByteToWideChar(CP_ACP,0,Src,-1,Dest,(int)DestSize)==0) |
| 92 | RetCode=false; |
| 93 | |
| 94 | // mbstowcs is broken in Android NDK r9. |
| 95 | #elif defined(_APPLE) |
| 96 | UtfToWide(Src,Dest,DestSize); |
| 97 | |
| 98 | #elif defined(MBFUNCTIONS) |
| 99 | mbstate_t ps; |
| 100 | memset (&ps, 0, sizeof(ps)); |
| 101 | const char *SrcParam=Src; // mbsrtowcs can change the pointer. |
| 102 | size_t ResultingSize=mbsrtowcs(Dest,&SrcParam,DestSize,&ps); |
| 103 | if (ResultingSize==(size_t)-1) |
| 104 | RetCode=false; |
| 105 | if (ResultingSize==0 && *Src!=0) |
| 106 | RetCode=false; |
| 107 | |
| 108 | if (RetCode==false && DestSize>1) |
| 109 | CharToWideMap(Src,Dest,DestSize,RetCode); |
| 110 | #else |
| 111 | for (int I=0;I<DestSize;I++) |
| 112 | { |
| 113 | Dest[I]=(wchar_t)Src[I]; |
| 114 | if (Src[I]==0) |
| 115 | break; |
| 116 | } |
| 117 | #endif |
| 118 | if (DestSize>0) |
| 119 | Dest[DestSize-1]=0; |
| 120 | |
| 121 | // We tried to return the empty string if conversion is failed, |
| 122 | // but it does not work well. MultiByteToWideChar returns 'failed' code |
| 123 | // even if we wanted to convert only a part of string and passed DestSize |
| 124 | // smaller than required for fully converted string. Such call is the valid |
| 125 | // behavior in RAR code and we do not expect the empty string in this case. |
| 126 | |
| 127 | return RetCode; |
| 128 | } |
| 129 | |
| 130 | |
| 131 | #if defined(_UNIX) && defined(MBFUNCTIONS) |
no test coverage detected