www.pudn.com > DTMS.rar > NEXTREC.C
#include "mail.h"
/* Return the next sequential record.
* We just step our way through the index file, ignoring deleted
* records. mail_rewind() must be called before this function
* is called the first time.
*/
char *
mail_nextrec(MAIL *mail, char *key)
{
char c, *ptr;
/* We read lock the free list so that we don't read
a record in the middle of its being deleted. */
if (readw_lock(mail->idxfd, FREE_OFF, SEEK_SET, 1) < 0)
err_dump("readw_lock error");
do {
/* read next sequential index record */
if (_mail_readidx(mail, 0,ANYIDX) < 0) {
ptr = NULL; /* end of index file, EOF */
goto doreturn;
}
/* check if key is all blank (empty record) */
ptr = mail->idxbuf;
while ( (c = *ptr++) != 0 && c == ' ')
; /* skip until null byte or nonblank */
} while (c == 0); /* loop until a nonblank key is found */
/*key=mail->idxbuf;*/
if (key != NULL)
strcpy(key, mail->idxbuf); /* return key */
ptr = _mail_readdat(mail); /* return pointer to data buffer */
mail->cnt_nextrec++;
doreturn:
if (un_lock(mail->idxfd, FREE_OFF, SEEK_SET, 1) < 0)
err_dump("un_lock error");
return(ptr);
}