move __string_read into vsscanf source file

apparently this function was intended at some point to be used by
strto* family as well, and thus was put in its own file; however, as
far as I can tell, it's only ever been used by vsscanf. move it to the
same file to reduce the number of source files and external symbols.
This commit is contained in:
Rich Felker 2020-04-17 16:18:07 -04:00
parent 2acf3bce01
commit 2e0907ce62
3 changed files with 13 additions and 21 deletions

View File

@ -60,8 +60,6 @@ hidden size_t __stdout_write(FILE *, const unsigned char *, size_t);
hidden off_t __stdio_seek(FILE *, off_t, int);
hidden int __stdio_close(FILE *);
hidden size_t __string_read(FILE *, unsigned char *, size_t);
hidden int __toread(FILE *);
hidden int __towrite(FILE *);

View File

@ -1,16 +0,0 @@
#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;
}

View File

@ -1,15 +1,25 @@
#include "stdio_impl.h"
#include <string.h>
static size_t do_read(FILE *f, unsigned char *buf, size_t len)
static size_t string_read(FILE *f, unsigned char *buf, size_t len)
{
return __string_read(f, buf, 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 = do_read, .lock = -1
.read = string_read, .lock = -1
};
return vfscanf(&f, fmt, ap);
}