Shanks0224 commented on code in PR #22179:
URL: https://github.com/apache/nuttx/pull/22179#discussion_r4676137749


##########
libs/libc/stdio/lib_libfflush.c:
##########
@@ -36,6 +36,33 @@
 
 #include "libc.h"
 
+/****************************************************************************
+ * Private Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: lib_fflush_rdflush
+ *
+ * Description:
+ *   Discard the read-ahead data of a stream and set the file offset of
+ *   the underlying file to the stream position.  A stream that cannot
+ *   seek (a pipe or a terminal) has no offset to restore, which is not
+ *   an error.
+ *
+ ****************************************************************************/
+
+#ifndef CONFIG_STDIO_DISABLE_BUFFERING
+static ssize_t lib_fflush_rdflush(FAR FILE *stream)
+{
+  if (lib_rdflush_unlocked(stream) < 0 && get_errno() != ESPIPE)

Review Comment:
   Fixed: the read data is discarded only when the file can seek, so a pipe or 
terminal keeps its buffer. stdin on a FIFO with getchar(), fflush(NULL), 
getchar() gives x, y, as on master and glibc. Now in #22241.
   



##########
libs/libc/stdio/lib_freopen.c:
##########
@@ -192,6 +197,10 @@ FAR FILE *freopen(FAR const char *path, FAR const char 
*mode,
           return NULL;
         }
 
+      /* Set the new file mode for the file stream */
+
+      stream->fs_oflags = oflags;

Review Comment:
   Fixed: the NULL path branch calls lib_fflush() before fcntl(F_SETFL). 
fdopen() "w", fputs("hello"), freopen(NULL, "r"), fclose() now writes the 5 
bytes.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to