libc: io: implement file io buffering and internal locking for concurrency
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#include "file.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int __libc_fctprintf(
|
||||
void (*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)
|
||||
{
|
||||
struct __opaque_file *fp = arg;
|
||||
__fputc(character, fp);
|
||||
}
|
||||
|
||||
int vprintf(const char *format, va_list arg)
|
||||
{
|
||||
__libc_file_lock(stdout);
|
||||
|
||||
int ret = __libc_fctprintf(_out_file, stdout, format, arg);
|
||||
|
||||
__libc_file_unlock(stdout);
|
||||
return ret;
|
||||
}
|
||||
Reference in New Issue
Block a user