musl - musl - an implementation of the standard library for Linux-based systems

index : musl
musl - an implementation of the standard library for Linux-based systems
summary refs log tree commit diff
path: root/src/stdio/feof.c
diff options
context:
space:
mode:
authorRich Felker <dalias@aerifal.cx>2012年10月24日 23:16:41 -0400
committerRich Felker <dalias@aerifal.cx>2012年10月24日 23:16:41 -0400
commitc8cb6bcdf009e94c12c6e256b8e24a9bc5fdaf05 (patch)
tree28d9441f99c5449267c987cb46b6610dc244a991 /src/stdio/feof.c
parent892cafff665b44d238e3b664f61ca38dd965cba6 (diff)
downloadmusl-c8cb6bcdf009e94c12c6e256b8e24a9bc5fdaf05.tar.gz
correct locking in stdio functions that tried to be lock-free
these functions must behave as if they obtain the lock via flockfile to satisfy POSIX requirements. since another thread can provably hold the lock when they are called, they must wait to obtain the lock before they can return, even if the correct return value could be obtained without locking. in the case of fclose and freopen, failure to do so could cause correct (albeit obscure) programs to crash or otherwise misbehave; in the case of feof, ferror, and fwide, failure to obtain the lock could sometimes return incorrect results. in any case, having these functions proceed and return while another thread held the lock was wrong.
Diffstat (limited to 'src/stdio/feof.c')
-rw-r--r--src/stdio/feof.c 5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/stdio/feof.c b/src/stdio/feof.c
index 5d7f4b02..56da6b91 100644
--- a/src/stdio/feof.c
+++ b/src/stdio/feof.c
@@ -4,7 +4,10 @@
int feof(FILE *f)
{
- return !!(f->flags & F_EOF);
+ FLOCK(f);
+ int ret = !!(f->flags & F_EOF);
+ FUNLOCK(f);
+ return ret;
}
weak_alias(feof, feof_unlocked);
generated by cgit v1.2.1 (git 2.18.0) at 2025年09月11日 03:50:02 +0000

AltStyle によって変換されたページ (->オリジナル) /