Changeset View
Changeset View
Standalone View
Standalone View
lib/libc/stdio/vsscanf.c
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | ||||||||||||
#include <sys/cdefs.h> | #include <sys/cdefs.h> | |||||||||||
__FBSDID("$FreeBSD$"); | __FBSDID("$FreeBSD$"); | |||||||||||
#include <stdio.h> | #include <stdio.h> | |||||||||||
#include <string.h> | #include <string.h> | |||||||||||
#include "local.h" | #include "local.h" | |||||||||||
#include "xlocale_private.h" | #include "xlocale_private.h" | |||||||||||
static int | struct _sscancookie { | |||||||||||
eofread(void *, char *, int); | FILE *fp; | |||||||||||
const char *str; | ||||||||||||
}; | ||||||||||||
static int _vsscanf_read(void *, char *, int); | ||||||||||||
#ifndef VSSCANF_CHUNK_SIZE | ||||||||||||
#define VSSCANF_CHUNK_SIZE 128 | ||||||||||||
#endif | ||||||||||||
pstef: Why do names of sscancookie and vsscanf_read() need to start with an underscore? | ||||||||||||
/* ARGSUSED */ | /* ARGSUSED */ | |||||||||||
static int | static int | |||||||||||
eofread(void *cookie, char *buf, int len) | _vsscanf_read(void *cookie, char *buf, int len) | |||||||||||
{ | { | |||||||||||
int n; | ||||||||||||
struct _sscancookie *sc; | ||||||||||||
sc = (struct _sscancookie *)cookie; | ||||||||||||
if (sc->str[0] == '\x00') | ||||||||||||
return (0); | return (0); | |||||||||||
n = strnlen(sc->str, VSSCANF_CHUNK_SIZE); | ||||||||||||
/* | ||||||||||||
* fp->_p is set in __srefill before calling us, this overwrites | ||||||||||||
* it so we don't have to copy the string into the buffer. | ||||||||||||
*/ | ||||||||||||
sc->fp->_p = (unsigned char *)sc->str; | ||||||||||||
sc->str += n; | ||||||||||||
return n; | ||||||||||||
Done Inline Actions
brooks: | ||||||||||||
} | } | |||||||||||
int | int | |||||||||||
vsscanf_l(const char * __restrict str, locale_t locale, | vsscanf_l(const char * __restrict str, locale_t locale, | |||||||||||
const char * __restrict fmt, __va_list ap) | const char * __restrict fmt, __va_list ap) | |||||||||||
{ | { | |||||||||||
FILE f = FAKE_FILE; | FILE f = FAKE_FILE; | |||||||||||
struct _sscancookie sc; | ||||||||||||
FIX_LOCALE(locale); | FIX_LOCALE(locale); | |||||||||||
f._flags = __SRD; | f._flags = __SRD; | |||||||||||
f._bf._base = f._p = (unsigned char *)str; | f._bf._base = f._p = (unsigned char *)str; | |||||||||||
f._bf._size = f._r = strlen(str); | f._bf._size = f._r = strnlen(str, VSSCANF_CHUNK_SIZE); | |||||||||||
f._read = eofread; | f._read = _vsscanf_read; | |||||||||||
sc = (struct _sscancookie){ | ||||||||||||
.str = str + f._r, | ||||||||||||
.fp = &f, | ||||||||||||
Done Inline ActionsI'd tend to swap these two lines to match the struct definition order. brooks: I'd tend to swap these two lines to match the struct definition order. | ||||||||||||
}; | ||||||||||||
f._cookie = ≻ | ||||||||||||
return (__svfscanf(&f, locale, fmt, ap)); | return (__svfscanf(&f, locale, fmt, ap)); | |||||||||||
} | } | |||||||||||
int | int | |||||||||||
vsscanf(const char * __restrict str, const char * __restrict fmt, | vsscanf(const char * __restrict str, const char * __restrict fmt, | |||||||||||
__va_list ap) | __va_list ap) | |||||||||||
{ | { | |||||||||||
return vsscanf_l(str, __get_locale(), fmt, ap); | return vsscanf_l(str, __get_locale(), fmt, ap); | |||||||||||
} | } |
Why do names of sscancookie and vsscanf_read() need to start with an underscore?