| 19 | #include "ts_lua_io.h" |
| 20 | |
| 21 | int64_t |
| 22 | IOBufferReaderCopy(TSIOBufferReader readerp, void *buf, int64_t length) |
| 23 | { |
| 24 | int64_t avail, need, n; |
| 25 | const char *start; |
| 26 | TSIOBufferBlock blk; |
| 27 | |
| 28 | n = 0; |
| 29 | blk = TSIOBufferReaderStart(readerp); |
| 30 | |
| 31 | while (blk) { |
| 32 | start = TSIOBufferBlockReadStart(blk, readerp, &avail); |
| 33 | need = length < avail ? length : avail; |
| 34 | |
| 35 | if (need > 0) { |
| 36 | memcpy((char *)buf + n, start, need); |
| 37 | length -= need; |
| 38 | n += need; |
| 39 | } |
| 40 | |
| 41 | if (length == 0) { |
| 42 | break; |
| 43 | } |
| 44 | |
| 45 | blk = TSIOBufferBlockNext(blk); |
| 46 | } |
| 47 | |
| 48 | return n; |
| 49 | } |
no test coverage detected