src/backend/utils/sort/logtape.c
/*
 * Read from a logical tape.
 *
 * Early EOF is indicated by return value less than #bytes requested.
 */
Read from a logical tape.
Early EOF is indicated by return value less than #bytes requested.
Read from a logical tape . Early EOF is indicated by return value less than #bytes requested .
size_t
LogicalTapeRead(LogicalTapeSet *lts, int tapenum,
				void *ptr, size_t size)
{
	LogicalTape *lt;
	size_t		nread = 0;
	size_t		nthistime;
	Assert(tapenum >= 0 && tapenum < lts->nTapes);
	lt = &lts->tapes[tapenum];
	Assert(!lt->writing);
	while (size > 0)
	{
		if (lt->pos >= lt->nbytes)
		{
			if (!ltsReadFillBuffer(lts, lt, -1))
				break;			
		}
		nthistime = lt->nbytes - lt->pos;
		if (nthistime > size)
			nthistime = size;
		Assert(nthistime > 0);
		memcpy(ptr, lt->buffer + lt->pos, nthistime);
		lt->pos += nthistime;
		ptr = (void *) ((char *) ptr + nthistime);
		size -= nthistime;
		nread += nthistime;
	}
	return nread;
}
size_t LogicalTapeRead ( LogicalTapeSet * lts , int tapenum , void * ptr , size_t size ) { LogicalTape * lt ; size_t nread = 0 ; size_t nthistime ; Assert ( tapenum >= 0 && tapenum < lts -> nTapes ) ; lt = & lts -> tapes [ tapenum ] ; Assert ( ! lt -> writing ) ; while ( size > 0 ) { if ( lt -> pos >= lt -> nbytes ) { if ( ! ltsReadFillBuffer ( lts , lt , -1 ) ) break ; } nthistime = lt -> nbytes - lt -> pos ; if ( nthistime > size ) nthistime = size ; Assert ( nthistime > 0 ) ; memcpy ( ptr , lt -> buffer + lt -> pos , nthistime ) ; lt -> pos += nthistime ; ptr = ( void * ) ( ( char * ) ptr + nthistime ) ; size -= nthistime ; nread += nthistime ; } return nread ; }
Read from a logical tape.
Read from a logical tape .
/* Try to load more data into buffer. */ /* EOF */