libc: io: vprintf now checks for stream error before returning
This commit is contained in:
@@ -1,19 +1,20 @@
|
||||
#include "file.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int __libc_fctprintf(
|
||||
void (*out)(char character, void *arg),
|
||||
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 void _out_file(char character, void *arg)
|
||||
static inline int _out_file(char character, void *arg)
|
||||
{
|
||||
struct __opaque_file *fp = arg;
|
||||
__fputc(character, fp);
|
||||
FILE *fp = arg;
|
||||
return __fputc(character, fp);
|
||||
}
|
||||
|
||||
int vprintf(const char *format, va_list arg)
|
||||
@@ -21,6 +22,13 @@ int vprintf(const char *format, va_list arg)
|
||||
__libc_file_lock(stdout);
|
||||
|
||||
int ret = __libc_fctprintf(_out_file, stdout, format, arg);
|
||||
if (errno != SUCCESS) {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
if (ferror(stdout)) {
|
||||
ret = -1;
|
||||
}
|
||||
|
||||
__libc_file_unlock(stdout);
|
||||
return ret;
|
||||
|
||||
Reference in New Issue
Block a user