提交 2e0907ce 编写于 作者: R Rich Felker

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.
上级 2acf3bce
......@@ -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 *);
......
#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;
}
#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);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册