X-Git-Url: http://git.archive.openwrt.org/?p=project%2Flibubox.git;a=blobdiff_plain;f=ustream.c;h=fc93bc21dd334de315e1849a9f8e478fe33c249e;hp=828a025b267bc30ba250d589842c1bd4ab6cb734;hb=827ad8337e88ec9e0bf73a8af1d6cf8555e8ef3d;hpb=c725f9f7a551bf31fd315d66c2a8a7fb8892b911 diff --git a/ustream.c b/ustream.c index 828a025..fc93bc2 100644 --- a/ustream.c +++ b/ustream.c @@ -333,6 +333,26 @@ char *ustream_get_read_buf(struct ustream *s, int *buflen) return data; } +int ustream_read(struct ustream *s, char *buf, int buflen) +{ + char *chunk; + int chunk_len; + int len = 0; + + do { + chunk = ustream_get_read_buf(s, &chunk_len); + if (!chunk) + break; + if (chunk_len > buflen - len) + chunk_len = buflen - len; + memcpy(buf + len, chunk, chunk_len); + ustream_consume(s, chunk_len); + len += chunk_len; + } while (len < buflen); + + return len; +} + static void ustream_write_error(struct ustream *s) { if (!s->write_error)