FILE* Dao_OpenFile( const char *file, const char *mode ) { #if _WIN32 DString file2 = DString_WrapChars( file ); DString mode2 = DString_WrapChars( mode ); DArray *file3 = DArray_New( sizeof(wchar_t) ); DArray *mode3 = DArray_New( sizeof(wchar_t) ); int ret1 = DString_DecodeUTF8( & file2, file3 ); int ret2 = DString_DecodeUTF8( & mode2, mode3 ); if( ret1 && ret2 ){ FILE *pfile = _wfopen( file3->data.wchars, mode3->data.wchars ); DArray_Delete( file3 ); DArray_Delete( mode3 ); return pfile; } DArray_Delete( file3 ); DArray_Delete( mode3 ); #endif return fopen( file, mode ); }
int Dao_FileStat( const char *path, struct stat *buf ) { #if _WIN32 DString path2 = DString_WrapChars( path ); DArray *path3 = DArray_New( sizeof(wchar_t) ); if( DString_DecodeUTF8( & path2, path3 ) ){ int ret = _wstat( path3->data.wchars, buf ); DArray_Delete( path3 ); return ret; } DArray_Delete( path3 ); #endif return stat( path, buf ); }
void DString_ToUpper( DString *self ) { daoint i; char *bytes; DArray *wcs; DString_Detach( self, self->size ); if( DString_IsASCII( self ) ){ for(i=0,bytes=self->chars; i<self->size; i++, bytes++) *bytes = toupper( *bytes ); return; } wcs = DArray_New( sizeof(wchar_t) ); DString_DecodeUTF8( self, wcs ); self->size = 0; for(i=0; i<wcs->size; ++i){ DString_AppendWChar( self, towupper( wcs->data.wchars[i] ) ); } DArray_Delete( wcs ); }