char* Binary_Stream::AllocSpaceWBack( vint32 sizeNeeded ) { // get number of bytes left from previous wback buffer vuint32 toget = vuint32(mWbacksize - mWbackcur); // allocate a buffer large enough to hold prev + new data char* temp_b = new char[sizeNeeded + toget]; if (!temp_b) return nullptr; // copy previous data (and free old buffer) if needed if (mWback) { memmove(temp_b + sizeNeeded, mWback + mWbackcur, toget); delete [] mWback; } // done mWback = temp_b; mWbackcur = 0; mWbacksize = vuint32(sizeNeeded + toget); return mWback; }
vuint32 Value_Raw::put_Length( vuint32 inNewLen ) { vuint32 Size = vuint32(m_pBufferEnd - m_pStart); vuint32 NewLen = inNewLen; if( NewLen > Size ) { NewLen = Size; } m_pEnd = m_pStart + NewLen; return vuint32(m_pEnd - m_pStart); }
String Value_datetime_imp::get_String( tslen inLimit ) const { String str; if( inLimit != 0 ) { UChar* p = str.getBuffer(kDateTimeStrMaxLength + 1); const DTFormat* pDTFormat = get_DTFormat(); Convert_datetime_str_fast( (DateTimeEncoded&)mValue, pDTFormat->mDateFormat, pDTFormat->mDateSep, pDTFormat->mTimeSep, p ); if( ((DateTimeEncoded&)mValue).encoded < 0 ) str.releaseBuffer(kDateTimeStrMaxLength); // 24 symbols for negative dates else str.releaseBuffer(kDateTimeStrMaxLength - 1); // 23 symbols for positive dates // not -1 and less than maxLen if( inLimit > 0 && vuint32(inLimit) < kDateTimeStrMaxLength ) { str.truncate( inLimit ); } } return str; }
vuint32 Binary_Stream::GetWBack( void* inBuff, vuint32 inSize ) { if (!mWback) return 0; // how many bytes do we have in the buffer? vuint32 toget = vuint32(mWbacksize - mWbackcur); if ( inSize < toget ) { // we won't read everything toget = inSize; } // copy the data from the cache memcpy(inBuff, mWback + mWbackcur, toget); mWbackcur += toget; if ( mWbackcur == mWbacksize ) { // TODO: should we really free it here all the time? maybe keep it? delete [] mWback; mWback = nullptr; mWbacksize = 0; mWbackcur = 0; } // return the number of bytes copied return toget; }
void Value_Raw::put_Data( vuint8* inDataBuffer, vuint32 inBufferSize ) { vuint8* pBegin = inDataBuffer; vuint8* pEnd = inDataBuffer + inBufferSize; if( pBegin == nullptr || inBufferSize == 0 ) { put_IsNull( true ); } else { put_IsNull( false ); vuint32 OldLen = get_Length(); vuint32 Available = get_Allocated(); vuint32 Assigned = vuint32(pEnd - pBegin); Assigned = Assigned > Available ? Available : Assigned; if( Assigned > 0) { memcpy( m_pStart, pBegin, Assigned ); m_pEnd = m_pStart + Assigned; } if( gEraseInformation ) { // Fill the peace of space that has been freed after old value with 0. vuint32 NewLen = get_Length(); vint32 Diff = static_cast<vint32>(OldLen - NewLen); if( Diff > 0 ) { memset(m_pEnd, 0, static_cast<vuint32>(Diff)); } } } }
void Value_Raw::put_String( const char* inBegin, const char* inEnd ) { if ( !inEnd ) inEnd = inBegin + strlen( inBegin ); vuint32 Len = vuint32(inEnd - inBegin); put_Data( (vuint8*)inBegin, Len ); }
FBL_Begin_Namespace /**********************************************************************************************/ #if FBL_MAC /**********************************************************************************************/ // NOTE: fullPath to item that EXISTS on disk. Otherwise file not found error. // #if FBL_SUPPORT_FSSPEC // OSErr Path2Spec_FSRef( const char *inPath, FSSpec *spec) { // parse path on parent folder and file name. const char* pFileName = ExtractNameFromFullPath(inPath); const char* pDelim = pFileName - 1; // String folder_path( inPath, vuint32(pDelim - inPath) ); vuint32 len; if( pDelim >= inPath ) len = vuint32(pDelim - inPath); else len = strlen( inPath ); MemPtr<char> folder_path( inPath, len + 1 ); folder_path[len] = 0; char* pFolderPath = folder_path.begin(); // convert the POSIX path to an FSRef of parent folder FSRef ref; OSStatus result = FSPathMakeRef( (vuint8*) pFolderPath, &ref, NULL); if( result != 0 ) return (OSErr) result; // and then convert the FSRef to an FSSpec FSSpec parent; result = FSGetCatalogInfo(&ref, kFSCatInfoNone, NULL, NULL, &parent, NULL); if( result != 0 ) return (OSErr) result; // now we have parent folder FSSpec, get its ID. vint32 theDirID; bool isDirectory; GetDirectoryID( parent.vRefNum, parent.parID, parent.name, &theDirID, &isDirectory ); // and now we make File spec: Str255 pasFileName; FBL::c2pstrcpy( pFileName, pasFileName ); result = FSMakeFSSpec( parent.vRefNum, theDirID, pasFileName, spec ); return (OSErr) result; }
void ArraySet::To( I_OStream_Ptr inStream, bool inBlock ) const { argused1(inBlock); // Type of set. inStream->put(vuint8(1)); if( mpStart ) { vuint32 allocLen = static_cast<vuint32>((mpStorageEnd - mpStart) * sizeof(vuint32)); vuint32 actualLen = static_cast<vuint32>((mpFinish - mpStart) * sizeof(vuint32)); // 1) Allocated len (in bytes). inStream->put(allocLen); if( actualLen > 0 ) { // 2) Actual len (in bytes). inStream->put(actualLen); // 3) Data of actual len. inStream->put((vuint8*)mpStart, actualLen); // 4) 'Sorted' flag. inStream->put(mIsSorted); } else { inStream->put( vuint32(0) ); } } else { inStream->put( vuint32(0) ); } }
const char* Value_Raw::AllocCopy( const char* inStart, const char* inEnd ) { FBL_CHECK( inStart <= inEnd ); vuint32 size = vuint32(inEnd - inStart); if( size ) { Alloc( size ); memcpy( m_pStart, inStart, size ); m_pEnd = m_pStart + size; } return m_pStart; }
void Value_Raw::put_ByteLength( vuint32 inNewLength ) { char* ps = m_pStart; char* pe = ps + inNewLength; m_pEnd = pe; // Fixed size Binary field should erase rest of buffer. // VarBinary field can skip this step, because into VarChar page will be // copies only data itself. if( this->get_Type() == kTypeFixedBinary ) { vuint32 leftBytes = vuint32( m_pBufferEnd - pe ); memset( pe, 0, leftBytes ); } }
void Value_Raw::To( I_OStream_Ptr inStream, bool inBlock ) const { argused1(inBlock); bool IsNull = bool( m_pStart == nullptr ); inStream->put(IsNull); if( !IsNull ) { vuint32 Len = vuint32(m_pEnd - m_pStart); inStream->put(Len); if( Len ) { inStream->put(reinterpret_cast<void*>(m_pStart), Len); } } }
void Value_Raw::To( I_PacketSnd* inPacket, bool inBlock ) const { argused1(inBlock); FixParamCount fixParamCount( inPacket ); bool IsNull = bool( m_pStart == nullptr ); inPacket->put_BoolParam(IsNull); if( !IsNull ) { vuint32 Len = vuint32(m_pEnd - m_pStart); inPacket->put_ULongParam(Len); if( Len ) { inPacket->put_BinaryParam(reinterpret_cast<void*>(m_pStart), Len); } } }
String Value_time_imp::get_String( tslen inLimit ) const { String str; if( inLimit != 0 ) { UChar* p = str.getBuffer(kTimeStrMaxLength + 1); const DTFormat* pDTFormat = get_DTFormat(); Convert_time_str_uu_fast( (TimeEncoded&)mValue, pDTFormat->mTimeSep, p ); str.releaseBuffer(kTimeStrMaxLength); // not -1 and less than maxLen if( inLimit > 0 && vuint32(inLimit) < kTimeStrMaxLength ) { str.truncate( inLimit ); } } return str; }
vuint32 Value_Raw::GrowBy( vuint32 inBySize ) { // For speed consideration this method does not perform // any checking of input parameters. vuint32 OldLen = get_Length(); vuint32 NewSize = get_Allocated() + inBySize; char* NewBuf = new char[NewSize]; if( !NewBuf ) { // Return the old size. return NewSize - inBySize; } // Copy and free old content memcpy(NewBuf, m_pStart, OldLen); delete []m_pStart; // Set pointers m_pStart = NewBuf; m_pBufferEnd = m_pStart + NewSize; m_pEnd = m_pStart + OldLen; if( gEraseInformation ) { // Fill additional memory with 0. vuint32 Rest = vuint32(m_pBufferEnd - m_pEnd); if( Rest ) { memset(m_pEnd, 0, Rest); } } return NewSize; }
bool DirData::Read( StringPtr outFilename, bool& outIsDirectory ) { if ( !m_isDir ) return false; outIsDirectory = false; vint16 err = noErr ; while ( err == noErr ) { m_index++ ; m_CPB.dirInfo.ioFDirIndex = m_index; m_CPB.dirInfo.ioDrDirID = m_dirId; /* we need to do this every time */ err = PBGetCatInfoSync((CInfoPBPtr)&m_CPB); if ( err != noErr ) break ; #if TARGET_CARBON // under X thats the way the mounting points look like if ( ( m_CPB.dirInfo.ioDrDirID == 0 ) && ( m_flags & DIR_DIRS) ) { outIsDirectory = true; break ; } #endif if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) != 0 && (m_flags & DIR_DIRS) ) // we have a directory { outIsDirectory = true; break ; } if ( ( m_CPB.dirInfo.ioFlAttrib & ioDirMask) == 0 && !(m_flags & DIR_FILES ) ) // its a file but we don't want it continue ; if ( ( m_CPB.hFileInfo.ioFlFndrInfo.fdFlags & kIsInvisible ) && !(m_flags & DIR_HIDDEN) ) // its hidden but we don't want it continue ; // COMMENTED, because this is code from wxWindows, it do pattern search of file names. We do not need this feature. /* String file( m_name ); if ( m_filespec.IsEmpty() || m_filespec == "*.*" || m_filespec == "*" ) { } else if ( m_filespec.GetLength() > 1 && m_filespec.Left(1) =="*" ) { if ( file.Right( m_filespec.GetLength() - 1 ).MakeUpper() != m_filespec.Mid(1).MakeUpper() ) { continue ; } } else if ( m_filespec.GetLength() > 1 && m_filespec.Right(1) == "*" ) { if ( file.Left( m_filespec.GetLength() - 1 ).MakeUpper() != m_filespec.Left( m_filespec.GetLength() - 1 ).MakeUpper() ) { continue ; } } else if ( file.MakeUpper() != m_filespec.MakeUpper() ) { continue ; }*/ break; } if ( err != noErr ) return false; memcpy( outFilename, m_name, vuint32(m_name[0] + 1) ); return true; }