Re: No error return in fprintf().
Thanks Fotis, I haven't had a chance to look at the code for stream_putc (i'm away from my computer and on my phone) but based on your description, it sounds like stream_putc should check and propagate errors. Even if the write to disk won't happen until later, any errors that are caught shouldn't be discarded. Nathan On Thu, Jul 20, 2023 at 3:56 PM Fotis Panagiotopoulos wrote: > Hello Nathan, > > Indeed, I should have mentioned that I have selected > CONFIG_STDIO_DISABLE_BUFFERING. > So, at least in my case, no buffering is taking place. > > But in the case of buffered output, I think that I agree that fprintf() may > return success for buffered (but not written) data. > > On Thu, Jul 20, 2023 at 10:16 PM Nathan Hartman > wrote: > > > On Thu, Jul 20, 2023 at 3:02 PM Fotis Panagiotopoulos < > f.j.pa...@gmail.com > > > > > wrote: > > > > > Hello, > > > > > > I am using fprintf() to output some data to a file. This file is > located > > on > > > an SD card. > > > > > > As I realised, fprintf() never returns an error. > > > > > > I tried to completely remove the SD card from the system, and fprintf > > > happily succeeds, > > > returning the number of bytes that it would have written, if the write > > was > > > successful. > > > > > > By checking the call trace, I see that the problem lies within > > > vsprintf_internal(). > > > It calls stream_putc() but no error checking is done there. > > > > > > Shouldn't this be considered a bug? > > > > > > > I haven't studied the code, so I may be off here, but... > > > > If fprintf() return code indicates success to my application, my > > expectation is that the data has been written. However it might be a > little > > more complicated than that: what if fprintf() successfully *buffered* the > > data and the fs layer is waiting for an opportunity to write it? In this > > scenario fprintf would return to the application before writing > completes. > > Then, it would be sensible for fprintf to indicate success (of the > > buffering) even though data wasn't actually stored on flash yet. Maybe a > > separate call to sync the fs is needed? > > > > Having said all that, stream_putc should probably do error checking and > > propagate errors. > > > > Cheers > > Nathan > > >
Re: No error return in fprintf().
Hello Nathan, Indeed, I should have mentioned that I have selected CONFIG_STDIO_DISABLE_BUFFERING. So, at least in my case, no buffering is taking place. But in the case of buffered output, I think that I agree that fprintf() may return success for buffered (but not written) data. On Thu, Jul 20, 2023 at 10:16 PM Nathan Hartman wrote: > On Thu, Jul 20, 2023 at 3:02 PM Fotis Panagiotopoulos > > wrote: > > > Hello, > > > > I am using fprintf() to output some data to a file. This file is located > on > > an SD card. > > > > As I realised, fprintf() never returns an error. > > > > I tried to completely remove the SD card from the system, and fprintf > > happily succeeds, > > returning the number of bytes that it would have written, if the write > was > > successful. > > > > By checking the call trace, I see that the problem lies within > > vsprintf_internal(). > > It calls stream_putc() but no error checking is done there. > > > > Shouldn't this be considered a bug? > > > > I haven't studied the code, so I may be off here, but... > > If fprintf() return code indicates success to my application, my > expectation is that the data has been written. However it might be a little > more complicated than that: what if fprintf() successfully *buffered* the > data and the fs layer is waiting for an opportunity to write it? In this > scenario fprintf would return to the application before writing completes. > Then, it would be sensible for fprintf to indicate success (of the > buffering) even though data wasn't actually stored on flash yet. Maybe a > separate call to sync the fs is needed? > > Having said all that, stream_putc should probably do error checking and > propagate errors. > > Cheers > Nathan >
Re: No error return in fprintf().
On Thu, Jul 20, 2023 at 3:02 PM Fotis Panagiotopoulos wrote: > Hello, > > I am using fprintf() to output some data to a file. This file is located on > an SD card. > > As I realised, fprintf() never returns an error. > > I tried to completely remove the SD card from the system, and fprintf > happily succeeds, > returning the number of bytes that it would have written, if the write was > successful. > > By checking the call trace, I see that the problem lies within > vsprintf_internal(). > It calls stream_putc() but no error checking is done there. > > Shouldn't this be considered a bug? > I haven't studied the code, so I may be off here, but... If fprintf() return code indicates success to my application, my expectation is that the data has been written. However it might be a little more complicated than that: what if fprintf() successfully *buffered* the data and the fs layer is waiting for an opportunity to write it? In this scenario fprintf would return to the application before writing completes. Then, it would be sensible for fprintf to indicate success (of the buffering) even though data wasn't actually stored on flash yet. Maybe a separate call to sync the fs is needed? Having said all that, stream_putc should probably do error checking and propagate errors. Cheers Nathan
No error return in fprintf().
Hello, I am using fprintf() to output some data to a file. This file is located on an SD card. As I realised, fprintf() never returns an error. I tried to completely remove the SD card from the system, and fprintf happily succeeds, returning the number of bytes that it would have written, if the write was successful. By checking the call trace, I see that the problem lies within vsprintf_internal(). It calls stream_putc() but no error checking is done there. Shouldn't this be considered a bug?