10 static const int EOF = -1;
20 int vdprintf(
int fd,
const char * format, va_list ap);
21 int vsprintf(
char * str,
const char * format, va_list ap);
22 int vsnprintf(
char * str,
size_t size,
const char * format, va_list ap);
23 int vasprintf(
char ** strp,
const char * format, va_list ap);
24 int vxprintf(
void (*func)(
const char *,
int,
void *),
void * arg,
const char * format, va_list ap);
25 static inline int vfprintf(
FILE * stream,
const char * format, va_list ap) {
return vdprintf(stream->
fd, format, ap); }
26 static inline int vprintf(
const char * format, va_list ap) {
return vfprintf(
stdout, format, ap); }
28 static inline int dprintf(
int fd,
const char * format, ...) { va_list ap;
int r; va_start(ap, format); r =
vdprintf(fd, format, ap); va_end(ap);
return r; }
29 static inline int sprintf(
char * str,
const char * format, ...) { va_list ap;
int r; va_start(ap, format); r =
vsprintf(str, format, ap); va_end(ap);
return r; }
30 static inline int snprintf(
char * str,
size_t size,
const char * format, ...) { va_list ap;
int r; va_start(ap, format); r =
vsnprintf(str, size, format, ap); va_end(ap);
return r; }
31 static inline int asprintf(
char ** strp,
const char * format, ...) { va_list ap;
int r; va_start(ap, format); r =
vasprintf(strp, format, ap); va_end(ap);
return r; }
32 static inline int xprintf(
void (*func)(
const char *,
int,
void *),
void * arg,
const char * format, ...) { va_list ap;
int r; va_start(ap, format); r =
vxprintf(func, arg, format, ap); va_end(ap);
return r; }
33 static inline int fprintf(
FILE * stream,
const char * format, ...) { va_list ap;
int r; va_start(ap, format); r = vfprintf(stream, format, ap); va_end(ap);
return r; }
34 static inline int printf(
const char * format, ...) { va_list ap;
int r; va_start(ap, format); r = vprintf(format, ap); va_end(ap);
return r; }
36 int vdscanf(
int fd,
const char * format, va_list ap);
37 int vsscanf(
const char * str,
const char * format, va_list ap);
38 int vxscanf(
int (*xgetc)(
void *),
void (*xungetc)(
void *,
int),
void * opaque,
const char * format, va_list args);
39 static inline int vfscanf(
FILE * stream,
const char * format, va_list ap) {
return vdscanf(stream->
fd, format, ap); }
40 static inline int vscanf(
const char * format, va_list ap) {
return vfscanf(
stdin, format, ap); }
42 static inline int dscanf(
int fd,
const char * format, ...) { va_list ap;
int r; va_start(ap, format); r =
vdscanf(fd, format, ap); va_end(ap);
return r; }
43 static inline int sscanf(
const char * str,
const char * format, ...) { va_list ap;
int r; va_start(ap, format); r =
vsscanf(str, format, ap); va_end(ap);
return r; }
44 static inline int xscanf(
int (*xgetc)(
void *),
void (*xungetc)(
void *,
int),
void * opaque,
const char *format, ...) { va_list ap;
int r; va_start(ap, format); r =
vxscanf(xgetc, xungetc, opaque, format, ap); va_end(ap);
return r; }
45 static inline int fscanf(
FILE * stream,
const char * format, ...) { va_list ap;
int r; va_start(ap, format); r = vfscanf(stream, format, ap); va_end(ap);
return r; }
46 static inline int scanf(
const char * format, ...) { va_list ap;
int r; va_start(ap, format); r = vscanf(format, ap); va_end(ap);
return r; }
53 static inline int fflush(
FILE *stream) {
return 0; }
56 static inline FILE * fopen(
const char * fname,
const char * mode) {
58 int flags = 0, plus = 0, append = 0,
fd;
59 if (!mode || !mode[0]) {
65 plus = mode[2] ==
'+';
116 static inline int fclose(
FILE * stream) {
131 static inline size_t fread(
void * _ptr,
size_t size,
size_t nmemb,
FILE * stream) {
133 uint8_t * ptr = (uint8_t *) _ptr;
142 r =
read(stream->
fd, ptr, nmemb);
149 r =
read(stream->
fd, ptr, size) == size ? 1 : 0;
155 for (i = 0; i < nmemb; i++) {
156 if (
read(stream->
fd, ptr + size * i, size) != size) {
165 static inline size_t fwrite(
const void * _ptr,
size_t size,
size_t nmemb,
FILE * stream) {
167 const uint8_t * ptr = (
const uint8_t *) _ptr;
175 return write(stream->
fd, ptr, nmemb);
178 return write(stream->
fd, ptr, size) == size ? 1 : 0;
180 for (i = 0; i < nmemb; i++) {
181 if (
write(stream->
fd, ptr + size * i, size) != size)
188 static inline int fgetc(
FILE * stream) {
196 if (
read(stream->
fd, &v, 1) != 1) {
203 static inline int fseek(
FILE * stream,
off_t offset,
int wheel) {
210 r =
lseek(stream->
fd, offset, wheel) != -1 ? 0 : -1;
216 static inline char * fgets(
char * s,
int n,
FILE * stream) {
250 static inline int getc() {
return fgetc(
stdin); }
252 static inline int feof(
FILE * stream) {
return stream->
got_eof; }
253 static inline int fileno(
FILE * stream) {
return stream->
fd; }
254 static inline void rewind(
FILE * stream) { fseek(stream, 0,
SEEK_SET); }