C++相談室 part81
■ このスレッドは過去ログ倉庫に格納されています
0381374
2010/05/21(金) 15:49:59std::wstring fullpath( std::wstring path){
unsigned int n;
if( memcmp( &path[0], L"\\\\\?\\", 8)!=0 ) {
if( (int)path.find(L":")!=-1) path=L"\\\\\?\\"+path;
else {
std::wstring root;
n=(1<<15); root.resize(n); n=GetCurrentDirectoryW(n, &root[0]); root.resize(n);
path = L"\\\\\?\\"+root + L"/" + path; } }
for( n=0; n<path.size(); n++ ) {
if( path[n]<32 ) { path[n]=L'_'; continue; }
if( path[n]==L'/' ) path[n]=L'\\';
}
return path; }
FILE* wfopen (std::wstring fname, std::wstring opt) {
int flg, att;
std::wstring fn=fullpath( fname );
att = GetFileAttributesW(&fn[0]);
if(att==-1) { if( opt[0]==L'r' ) return NULL; else att=0; }
if(opt[0]==L'a' || opt[0]==L'r' ) flg=OPEN_ALWAYS; else flg=CREATE_ALWAYS;
HANDLE hd=CreateFileW( &fn[0], GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ , NULL , flg , att , NULL);
return _wfdopen( _open_osfhandle ( (int)hd, 0 ), &opt[0] ); }
FILE* wfopen (std::string fn, std::string opt) { return wfopen( char2wchar(fn), char2wchar(opt) ); }
■ このスレッドは過去ログ倉庫に格納されています