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