libc: io: implement file io buffering and internal locking for concurrency
This commit is contained in:
@@ -7,7 +7,9 @@ char *fgets(
|
||||
int count,
|
||||
struct __opaque_file *restrict stream)
|
||||
{
|
||||
__libc_file_lock(stream);
|
||||
if (stream->f_flags & (FILE_EOF | FILE_ERR)) {
|
||||
__libc_file_unlock(stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -28,13 +30,16 @@ char *fgets(
|
||||
}
|
||||
}
|
||||
|
||||
if (ferr(stream)) {
|
||||
if (ferror(stream)) {
|
||||
__libc_file_unlock(stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (feof(stream) && i == 0) {
|
||||
__libc_file_unlock(stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
__libc_file_unlock(stream);
|
||||
return str;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user