Rich Felker | 18efeb3 | 2012-04-16 16:03:45 -0400 | [diff] [blame] | 1 | #include "stdio_impl.h" |
Rich Felker | 835f9f9 | 2012-11-08 16:39:41 -0500 | [diff] [blame] | 2 | #include <string.h> |
Rich Felker | 18efeb3 | 2012-04-16 16:03:45 -0400 | [diff] [blame] | 3 | |
| 4 | size_t __string_read(FILE *f, unsigned char *buf, size_t len) |
| 5 | { |
| 6 | char *src = f->cookie; |
Rich Felker | 8b57a81 | 2012-04-17 13:17:01 -0400 | [diff] [blame] | 7 | size_t k = len+256; |
| 8 | char *end = memchr(src, 0, k); |
| 9 | if (end) k = end-src; |
Rich Felker | 18efeb3 | 2012-04-16 16:03:45 -0400 | [diff] [blame] | 10 | if (k < len) len = k; |
| 11 | memcpy(buf, src, len); |
| 12 | f->rpos = (void *)(src+len); |
| 13 | f->rend = (void *)(src+k); |
| 14 | f->cookie = src+k; |
| 15 | return len; |
| 16 | } |