static void InsertBlockIntoPositionList(void* block) { void* current, *previous; current = GetFirstBlock(); if ((char*)block < (char*)current) /* Make this the head of the list */ { ((struct FreeListElement*) current)->positionprev = RELATIVEPOINTER(block); ((struct FreeListElement*) block)->positionnext = RELATIVEPOINTER(current); FreePositionHead = block; } else /* Insert somewhere in the middle */ { do { previous = current; /* We need to keep a chaising pointer to be able to add to the end of the list. */ current = GetNextBlock(current); } while (current && ((char*)block < (char*)current)); if (current) { ((struct FreeListElement*) current)->positionprev = RELATIVEPOINTER(block); ((struct FreeListElement*) previous)->positionnext = RELATIVEPOINTER(block); ((struct FreeListElement*) block)->positionprev = RELATIVEPOINTER(previous); ((struct FreeListElement*) block)->positionnext = RELATIVEPOINTER(current); } else /* Add to the end of the list */ { ((struct FreeListElement*) previous)->positionnext = RELATIVEPOINTER(block); ((struct FreeListElement*) block)->positionprev = RELATIVEPOINTER(previous); ((struct FreeListElement*) block)->positionnext = 0; } } }
bool CTapFile::GetBlock(word blkIdx, CTapeBlock* tb) { return blkIdx < GetBlockCount() && Seek(blkIdx) && (blkIdx == 0 ? GetFirstBlock(tb) : GetNextBlock(tb)); }