Mercurial > mplayer.hg
diff libmpdemux/stream.h @ 17879:0ca3fb62d2da
Move the subread from FILE to stream_t.
author | albeu |
---|---|
date | Thu, 16 Mar 2006 14:42:51 +0000 |
parents | 80bc92fd883a |
children | c0fa48581ccf |
line wrap: on
line diff
--- a/libmpdemux/stream.h Thu Mar 16 14:24:22 2006 +0000 +++ b/libmpdemux/stream.h Thu Mar 16 14:42:51 2006 +0000 @@ -208,6 +208,31 @@ return total; } +inline static unsigned char* stream_read_line(stream_t *s,unsigned char* mem, int max) { + int len; + unsigned char* end,*ptr = mem;; + do { + len = s->buf_len-s->buf_pos; + // try to fill the buffer + if(len <= 0 && + (!cache_stream_fill_buffer(s) || + (len = s->buf_len-s->buf_pos) <= 0)) break; + end = memchr((void*)(s->buffer+s->buf_pos),'\n',len); + if(end) len = end - (s->buffer+s->buf_pos) + 1; + if(len > 0 && max > 1) { + int l = len > max-1 ? max-1 : len; + memcpy(ptr,s->buffer+s->buf_pos,l); + max -= l; + ptr += l; + } + s->buf_pos += len; + } while(!end); + if(s->eof && ptr == mem) return NULL; + if(max > 0) ptr[0] = 0; + return mem; +} + + inline static int stream_eof(stream_t *s){ return s->eof; }