int STREAMCheckForBytes(STREAM *S) { if (! S) return(0); if (S->State & SS_EMBARGOED) return(0); if (S->InEnd > S->InStart) return(1); if (S->in_fd==-1) return(0); return(FDCheckForBytes(S->in_fd)); }
int STREAMReadBytes(STREAM *S, char *Buffer, int Buffsize) { char *ptr=NULL; int bytes=0, result=0, total=0; ptr=Buffer; if (S->InStart >= S->InEnd) { result=STREAMReadCharsToBuffer(S); if (S->InStart >= S->InEnd) { if (result==STREAM_CLOSED) return(EOF); if (result==STREAM_TIMEOUT) return(STREAM_TIMEOUT); if (result==STREAM_DATA_ERROR) return(STREAM_DATA_ERROR); } } while (total < Buffsize) { total+=STREAMTransferBytesOut(S, Buffer+total, Buffsize-total); bytes=S->InEnd - S->InStart; if (bytes < 1) { //in testing, the best way to prevent doing constant checking for new bytes, //and so filling up the buffer, was to only check for new bytes if //we didn't have enough to satisfy another read like the one we just had //We must check for '< 1' rather than '-1' because result=FDCheckForBytes(S->in_fd); if (result ==-1) { if (total==0) total=EOF; break; } if (result < 1) break; result=STREAMReadCharsToBuffer(S); if (result < 1) { if (total > 0) return(total); else return(result); } } } return(total); }
int STREAMCountWaitingBytes(STREAM *S) { int read_result=0, result; if (! S) return(0); if (S->State & SS_EMBARGOED) return(0); result=FDCheckForBytes(S->in_fd); if (result > 0) read_result=STREAMReadCharsToBuffer(S); else if (result < 0) read_result=STREAM_CLOSED; result=S->InEnd - S->InStart; if (result > 0) return(result); if (read_result==STREAM_CLOSED) return(EOF); if (read_result==STREAM_DATA_ERROR) return(EOF); return(0); }
int STREAMCheckForBytes(STREAM *S) { off_t pos; struct stat Stat; if (! S) return(FALSE); if (S->State & SS_EMBARGOED) return(FALSE); if (S->InEnd > S->InStart) return(TRUE); if (S->in_fd==-1) return(FALSE); if (S->Flags & SF_FOLLOW) { while (1) { pos=STREAMTell(S); fstat(S->in_fd,&Stat); if (Stat.st_size > pos) return(TRUE); } } return(FDCheckForBytes(S->in_fd)); }
int STREAMCheckForWaitingChar(STREAM *S,unsigned char check_char) { int read_result=0, result, trash; char *found_char; if (! S) return(0); if (S->State & SS_EMBARGOED) return(0); result=FDCheckForBytes(S->in_fd); if (result > 0) read_result=STREAMReadCharsToBuffer(S); else if (result < 0) read_result=STREAM_CLOSED; if (S->InStart < S->InEnd) { found_char=memchr(S->InputBuff + S->InStart,check_char,S->InEnd - S->InStart); if (found_char > 0) return(TRUE); } if (read_result==STREAM_CLOSED) return(EOF); if (read_result==STREAM_DATA_ERROR) return(EOF); return(FALSE); }