bool fal_unlink( const String &filename, int32 &fsStatus ) { String fname = filename; Path::uriToWin( fname ); AutoWString wBuffer( fname ); BOOL res = DeleteFileW( wBuffer.w_str() ); if( ! res && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) { AutoCString cBuffer( fname ); res = DeleteFile( cBuffer.c_str() ); } if ( res == TRUE ) { return true; } fsStatus = GetLastError(); return false; }
bool fal_mkdir( const String &filename, int32 &fsStatus ) { String fname = filename; Path::uriToWin( fname ); AutoWString wBuffer( fname ); BOOL res = CreateDirectoryW( wBuffer.w_str(), NULL ); if( ! res && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) { AutoCString cBuffer( fname ); res = CreateDirectory( cBuffer.c_str(), NULL ); } if ( res == TRUE ) { return true; } fsStatus = GetLastError(); return false; }
::Falcon::DirEntry *fal_openDir( const String &path, int32 &fsError ) { String fname = path + "\\*"; Path::uriToWin( fname ); AutoWString wBuffer( fname ); WIN32_FIND_DATAW dir_data; HANDLE handle = FindFirstFileW( wBuffer.w_str(), &dir_data ); if( handle == INVALID_HANDLE_VALUE && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) { AutoCString cBuffer( fname ); handle = FindFirstFile( cBuffer.c_str(), (WIN32_FIND_DATA*) &dir_data ); } if ( handle != INVALID_HANDLE_VALUE ) return new DirEntry_win( path, handle, dir_data ); fsError = GetLastError(); return 0; }
bool fal_stats( const String &filename, FileStat &sts ) { String fname = filename; Path::uriToWin( fname ); AutoWString wBuffer( fname ); // First, determine if the file exists if( filename.size() > 0 && filename.getCharAt(filename.length()-1) != '.' ) { WIN32_FIND_DATAW wFindData; HANDLE hFound = FindFirstFileW( wBuffer.w_str(), &wFindData ); if( hFound == INVALID_HANDLE_VALUE ) { if( GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) { WIN32_FIND_DATAA aFindData; AutoCString cBuffer( fname ); hFound = FindFirstFileA( cBuffer.c_str(), &aFindData ); if ( hFound == INVALID_HANDLE_VALUE ) return false; FindClose( hFound ); // check case sensitive String ffound(aFindData.cFileName); if( fname.subString( fname.length() - ffound.length() ) != ffound ) return false; } else return false; } FindClose( hFound ); // Then, see if the case matches. String ffound(wFindData.cFileName); if( fname.subString( fname.length() - ffound.length() ) != ffound ) return false; } // ok, file exists and with matching case HANDLE temp = CreateFileW( wBuffer.w_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); if( (temp == INVALID_HANDLE_VALUE || temp == 0) && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) { AutoCString cBuffer( fname ); temp = CreateFile( cBuffer.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, NULL ); } if( temp == INVALID_HANDLE_VALUE ) { // on win 95/98, we can't normally access directory data. DWORD attribs = GetFileAttributesW( wBuffer.w_str() ); if( attribs == INVALID_FILE_ATTRIBUTES && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED ) { AutoCString cBuffer( fname ); attribs = GetFileAttributes( cBuffer.c_str() ); } if( attribs == INVALID_FILE_ATTRIBUTES ) { return false; } if( (attribs & FILE_ATTRIBUTE_DIRECTORY) == FILE_ATTRIBUTE_DIRECTORY ) { sts.m_type = FileStat::t_dir; sts.m_attribs = attribs; sts.m_size = 0; sts.m_mtime = new TimeStamp(); sts.m_atime = new TimeStamp(); sts.m_ctime = new TimeStamp(); sts.m_owner = 0; /* user ID of owner */ sts.m_group = 0; /* group ID of owner */ return true; } return false; } BY_HANDLE_FILE_INFORMATION info; memset( &info, 0, sizeof( info ) ); GetFileInformationByHandle( temp, &info ); if( info.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY ) sts.m_type = FileStat::t_dir; else sts.m_type = FileStat::t_normal; FILETIME local_timing; SYSTEMTIME timing; FileTimeToLocalFileTime( &info.ftCreationTime, &local_timing ); FileTimeToSystemTime( &local_timing, &timing ); WinSystemTime mtime( timing ); if ( sts.m_ctime == 0 ) sts.m_ctime = new TimeStamp(); sts.m_ctime->fromSystemTime( mtime ); FileTimeToLocalFileTime( &info.ftLastAccessTime, &local_timing ); FileTimeToSystemTime( &local_timing, &mtime.m_time ); if ( sts.m_atime == 0 ) sts.m_atime = new TimeStamp(); sts.m_atime->fromSystemTime( mtime ); FileTimeToLocalFileTime( &info.ftLastWriteTime, &local_timing ); FileTimeToSystemTime( &local_timing, &mtime.m_time ); if ( sts.m_mtime == 0 ) sts.m_mtime = new TimeStamp(); sts.m_mtime->fromSystemTime( mtime ); sts.m_size = info.nFileSizeHigh; sts.m_size = sts.m_size << 32 | info.nFileSizeLow; sts.m_attribs = info.dwFileAttributes; sts.m_owner = 0; /* user ID of owner */ sts.m_group = 0; /* group ID of owner */ CloseHandle( temp ); return true; }
/* * Process the color table for the bmp input */ bool SkBmpRLECodec::createColorTable(int* numColors) { // Allocate memory for color table uint32_t colorBytes = 0; SkPMColor colorTable[256]; if (this->bitsPerPixel() <= 8) { // Inform the caller of the number of colors uint32_t maxColors = 1 << this->bitsPerPixel(); if (NULL != numColors) { // We set the number of colors to maxColors in order to ensure // safe memory accesses. Otherwise, an invalid pixel could // access memory outside of our color table array. *numColors = maxColors; } // Read the color table from the stream colorBytes = fNumColors * fBytesPerColor; SkAutoTDeleteArray<uint8_t> cBuffer(SkNEW_ARRAY(uint8_t, colorBytes)); if (stream()->read(cBuffer.get(), colorBytes) != colorBytes) { SkCodecPrintf("Error: unable to read color table.\n"); return false; } // Fill in the color table uint32_t i = 0; for (; i < fNumColors; i++) { uint8_t blue = get_byte(cBuffer.get(), i*fBytesPerColor); uint8_t green = get_byte(cBuffer.get(), i*fBytesPerColor + 1); uint8_t red = get_byte(cBuffer.get(), i*fBytesPerColor + 2); colorTable[i] = SkPackARGB32NoCheck(0xFF, red, green, blue); } // To avoid segmentation faults on bad pixel data, fill the end of the // color table with black. This is the same the behavior as the // chromium decoder. for (; i < maxColors; i++) { colorTable[i] = SkPackARGB32NoCheck(0xFF, 0, 0, 0); } // Set the color table fColorTable.reset(SkNEW_ARGS(SkColorTable, (colorTable, maxColors))); } // Check that we have not read past the pixel array offset if(fOffset < colorBytes) { // This may occur on OS 2.1 and other old versions where the color // table defaults to max size, and the bmp tries to use a smaller // color table. This is invalid, and our decision is to indicate // an error, rather than try to guess the intended size of the // color table. SkCodecPrintf("Error: pixel data offset less than color table size.\n"); return false; } // After reading the color table, skip to the start of the pixel array if (stream()->skip(fOffset - colorBytes) != fOffset - colorBytes) { SkCodecPrintf("Error: unable to skip to image data.\n"); return false; } // Return true on success return true; }
cBuffer InvalidOpcodeByte::getOpcode() const { return cBuffer(&m_invalidOpcode, 1); }