summaryrefslogblamecommitdiff
path: root/src/stdio/vsscanf.c
blob: 4d6d259b8291a6af68e101d871ac7d4b2f8373e9 (plain) (tree)
1
2
3
4
5
                       
                   
 
                                                                  
 









                                      

 
                                                                         
 

                                                      
                                               

                                    
 

                                     
#include "stdio_impl.h"
#include <string.h>

static 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;
}

int vsscanf(const char *restrict s, const char *restrict fmt, va_list ap)
{
	FILE f = {
		.buf = (void *)s, .cookie = (void *)s,
		.read = string_read, .lock = -1
	};
	return vfscanf(&f, fmt, ap);
}

weak_alias(vsscanf,__isoc99_vsscanf);