36 lines
616 B
C
36 lines
616 B
C
|
|
#include "file.h"
|
||
|
|
|
||
|
|
#include <errno.h>
|
||
|
|
#include <stddef.h>
|
||
|
|
#include <stdio.h>
|
||
|
|
|
||
|
|
extern int __libc_fctprintf(
|
||
|
|
int (*out)(char character, void *arg),
|
||
|
|
void *arg,
|
||
|
|
const char *format,
|
||
|
|
va_list va);
|
||
|
|
extern int __fputc(int c, struct __opaque_file *stream);
|
||
|
|
|
||
|
|
static inline int _out_file(char character, void *arg)
|
||
|
|
{
|
||
|
|
FILE *fp = arg;
|
||
|
|
return __fputc(character, fp);
|
||
|
|
}
|
||
|
|
|
||
|
|
int vfprintf(FILE *fp, const char *format, va_list arg)
|
||
|
|
{
|
||
|
|
__libc_file_lock(fp);
|
||
|
|
|
||
|
|
int ret = __libc_fctprintf(_out_file, fp, format, arg);
|
||
|
|
if (errno != SUCCESS) {
|
||
|
|
ret = -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
if (ferror(fp)) {
|
||
|
|
ret = -1;
|
||
|
|
}
|
||
|
|
|
||
|
|
__libc_file_unlock(fp);
|
||
|
|
return ret;
|
||
|
|
}
|