summaryrefslogtreecommitdiff
path: root/src/stdio/__string_read.c
blob: 7b50a7e1154224a40ddcbb204a429eb74380ffc9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include "stdio_impl.h"
#include <string.h>

size_t __string_read(FILE *f, unsigned char *buf, size_t len)
{
	char *src = f->cookie;
	size_t k = len+256;
	char *end = memchr(src, 0, k);
	if (end) k = end-src;
	if (k < len) len = k;
	memcpy(buf, src, len);
	f->rpos = (void *)(src+len);
	f->rend = (void *)(src+k);
	f->cookie = src+k;
	return len;
}