/* Buffering mode used by setvbuf. */ #define _IOFBF 0 /* Fully buffered. */ #define _IOLBF 1 /* Line buffered. */ #define _IONBF 2 /* No buffering. */
/* just define FILE as a non-empty type. The value of the pointer gives * the FD: FILE=~fd for fd>=0 or NULL for fd<0. This way positive FILE * are immediately identified as abnormal entries (i.e. possible copies * of valid pointers to something else).
*/ typedefstruct FILE { char dummy[1];
} FILE;
static __attribute__((unused)) int putchar(int c)
{ return fputc(c, stdout);
}
/* fwrite(), puts(), fputs(). Note that puts() emits '\n' but not fputs(). */
/* internal fwrite()-like function which only takes a size and returns 0 on * success or EOF on error. It automatically retries on short writes.
*/ static __attribute__((unused)) int _fwrite(constvoid *buf, size_t size, FILE *stream)
{
ssize_t ret; int fd = fileno(stream);
while (size) {
ret = write(fd, buf, size); if (ret <= 0) return EOF;
size -= ret;
buf += ret;
} return 0;
}
written = ofs = escape = lpref = 0; while (1) {
c = fmt[ofs++];
width = 0;
if (escape) { /* we're in an escape sequence, ofs == 1 */
escape = 0;
/* width */ while (c >= '0' && c <= '9') {
width *= 10;
width += c - '0';
c = fmt[ofs++];
}
if (c == 'c' || c == 'd' || c == 'u' || c == 'x' || c == 'p') { char *out = tmpbuf;
if (c == 'p')
v = va_arg(args, unsignedlong); elseif (lpref) { if (lpref > 1)
v = va_arg(args, unsignedlonglong); else
v = va_arg(args, unsignedlong);
} else
v = va_arg(args, unsignedint);
if (c == 'd') { /* sign-extend the value */ if (lpref == 0)
v = (longlong)(int)v; elseif (lpref == 1)
v = (longlong)(long)v;
}
/* not an escape sequence */ if (c == 0 || c == '%') { /* flush pending data on escape or end */
escape = 1;
lpref = 0;
outstr = fmt;
len = ofs - 1;
flush_str: if (n) {
w = len < n ? len : n;
n -= w; while (width-- > w) { if (cb(state, " ", 1) != 0) return -1;
written += 1;
} if (cb(state, outstr, w) != 0) return -1;
}
written += len;
do_escape: if (c == 0) break;
fmt += ofs;
ofs = 0; continue;
}
/* literal char, just queue it */
} return written;
}
stream = fdopen(fd, NULL); if (!stream) return -1; /* Technically 'stream' is leaked, but as it's only a wrapper around 'fd' that is fine */ return vfprintf(stream, fmt, args);
}
static __attribute__((unused, format(printf, 2, 3))) int dprintf(int fd, constchar *fmt, ...)
{
va_list args; int ret;
va_start(args, fmt);
ret = vdprintf(fd, fmt, args);
va_end(args);
static __attribute__((unused)) int setvbuf(FILE *stream __attribute__((unused)), char *buf __attribute__((unused)), int mode,
size_t size __attribute__((unused)))
{ /* * nolibc does not support buffering so this is a nop. Just check mode * is valid as required by the spec.
*/ switch (mode) { case _IOFBF: case _IOLBF: case _IONBF: break; default: return EOF;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.