You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by GitBox <gi...@apache.org> on 2021/06/14 08:06:33 UTC

[GitHub] [incubator-nuttx] fjpanag opened a new issue #3915: Reopening a file does not clear I/O buffers.

fjpanag opened a new issue #3915:
URL: https://github.com/apache/incubator-nuttx/issues/3915


   If I use I/O buffering (CONFIG_STDIO_DISABLE_BUFFERING = n), then the following piece of code fails.
   
   ```c
   int c1;
   int c2;
   
   FILE * file = fopen("/file", "r");
   c1 = getc(file);
   
   file = freopen("/file", "rb");
   c2 = getc(file);
   
   assert(c1 == c2);
   ```
   
   When the file is re-opened, the file index does not return to zero. `c2` gets the *second* character in the file, as it was found in the buffer (the file is not re-read).
   
   Recompiling the code with `CONFIG_STDIO_DISABLE_BUFFERING` selected (no I/O buffering), the problem is solved.  
   When I reopen the file, I get the first character of the file, as expected.
   
   When a file is re-opened, shouldn't the I/O buffers be cleared?
   


-- 
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.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [incubator-nuttx] pkarashchenko commented on issue #3915: Reopening a file does not clear I/O buffers.

Posted by GitBox <gi...@apache.org>.
pkarashchenko commented on issue #3915:
URL: https://github.com/apache/incubator-nuttx/issues/3915#issuecomment-996888999


   From the example I see that `file = freopen("/file", "rb");` is used, but `FAR FILE *freopen(FAR const char *path, FAR const char *mode, FAR FILE *stream);`, so the last parameter is missing in the example. Is the case incomplete?


-- 
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: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org