]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
read-file: disable buffering if RF_SENSITIVE is set
authorDaiki Ueno <ueno@gnu.org>
Fri, 29 May 2020 03:45:40 +0000 (05:45 +0200)
committerDaiki Ueno <ueno@gnu.org>
Fri, 29 May 2020 15:20:15 +0000 (17:20 +0200)
* 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.

ChangeLog
lib/read-file.c

index 566dfabbc2bde377be25f22e07e88db783a22acd..9ff3543225a52307b905aa5dbc1c7a70263141df 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2020-05-29  Daiki Ueno  <ueno@gnu.org>
+
+       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.
+
 2020-05-29  Bruno Haible  <bruno@clisp.org>
 
        wmemchr, wmemcmp, wmemcpy, wmemmove, wmemset: Fix autoconf test.
index 36780cc1571281e51fc58e348c650ebd35f9cf94..88bc0070a9359f066eb2d753140a099d609334b2 100644 (file)
    *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;