libc: io: implement file io buffering and internal locking for concurrency
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
#include "file.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
int __fputc(int c, struct __opaque_file *stream)
|
||||
{
|
||||
if (stream->f_flags & (FILE_EOF | FILE_ERR)) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
char cv = c;
|
||||
int ret = __libc_file_write(stream, &cv, 1);
|
||||
if (ret < 1) {
|
||||
return EOF;
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
int fputc(int c, struct __opaque_file *stream)
|
||||
{
|
||||
__libc_file_lock(stream);
|
||||
int ret = __fputc(c, stream);
|
||||
__libc_file_unlock(stream);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user