libc: io: implement file io buffering and internal locking for concurrency
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
#include "file.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stdio.h>
|
||||
|
||||
extern int setvbuf(
|
||||
struct __opaque_file *restrict stream,
|
||||
char *restrict buf,
|
||||
int mode,
|
||||
size_t size)
|
||||
{
|
||||
switch (mode) {
|
||||
case _IOFBF:
|
||||
case _IOLBF:
|
||||
case _IONBF:
|
||||
break;
|
||||
default:
|
||||
return __set_errno(EINVAL);
|
||||
}
|
||||
|
||||
if (stream->f_prev != 0) {
|
||||
return __set_errno(EINVAL);
|
||||
}
|
||||
|
||||
int err = SUCCESS;
|
||||
if (buf) {
|
||||
err = __libc_ringbuf_resize_static(&stream->f_buf, buf, size);
|
||||
} else {
|
||||
err = __libc_ringbuf_resize(&stream->f_buf, size);
|
||||
}
|
||||
|
||||
if (err != SUCCESS) {
|
||||
return __set_errno(err);
|
||||
}
|
||||
|
||||
stream->f_buffer_mode = mode;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user