summaryrefslogtreecommitdiff
path: root/lib/read-file.c
diff options
context:
space:
mode:
authorDaiki Ueno <ueno@gnu.org>2020-05-29 05:45:40 +0200
committerDaiki Ueno <ueno@gnu.org>2020-05-29 17:20:15 +0200
commitfb64a78174042189f4d012cbd748d565f021cd69 (patch)
tree67c3d5444b83a797aa6f17c6678cf98b989fa0fc /lib/read-file.c
parent26dab349c2da7df56ae5e165163d0211277c4676 (diff)
downloadgnulib-fb64a78174042189f4d012cbd748d565f021cd69.tar.gz
read-file: disable buffering if RF_SENSITIVE is set
* lib/read-file.c (read_file): Call setvbuf if RF_SENSITIVE. Suggested by Glenn Strauss. (fread_file): Suggest calling setvbuf before calling this function. Suggested by Bruno Haible.
Diffstat (limited to 'lib/read-file.c')
-rw-r--r--lib/read-file.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/lib/read-file.c b/lib/read-file.c
index 36780cc157..88bc0070a9 100644
--- a/lib/read-file.c
+++ b/lib/read-file.c
@@ -43,8 +43,11 @@
*LENGTH. On errors, *LENGTH is undefined, errno preserves the
values set by system functions (if any), and NULL is returned.
- If the RF_SENSITIVE flag is set in FLAGS, the memory buffer
- internally allocated will be cleared upon failure. */
+ If the RF_SENSITIVE flag is set in FLAGS:
+ - You should control the buffering of STREAM using 'setvbuf'. Either
+ clear the buffer of STREAM after closing it, or disable buffering of
+ STREAM before calling this function.
+ - The memory buffer internally allocated will be cleared upon failure. */
char *
fread_file (FILE *stream, int flags, size_t *length)
{
@@ -195,6 +198,9 @@ read_file (const char *filename, int flags, size_t *length)
if (!stream)
return NULL;
+ if (flags & RF_SENSITIVE)
+ setvbuf (stream, NULL, _IONBF, 0);
+
out = fread_file (stream, flags, length);
save_errno = errno;