ulog: implement ulog_close()
[project/libubox.git] / ustream.c
index dfbee1a..fc93bc2 100644 (file)
--- a/ustream.c
+++ b/ustream.c
@@ -276,7 +276,7 @@ static bool ustream_prepare_buf(struct ustream *s, struct ustream_buf_list *l, i
 
 char *ustream_reserve(struct ustream *s, int len, int *maxlen)
 {
-       struct ustream_buf *buf = s->r.head;
+       struct ustream_buf *buf;
 
        if (!ustream_prepare_buf(s, &s->r, len)) {
                __ustream_set_read_blocked(s, s->read_blocked | READ_BLOCKED_FULL);
@@ -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)