Check the return value of each call on fprintf() and fwrite() . If any of the calls returns a negative value, check errno to see if errno is equal to EDQUOT or ENOSPC , see the manpage for writing (or in the case of fprintf() may even be ENOMEM , as indicated in some manpages for fprintf , but not all ) If so, you are probably out of disk space.
As for the resumption of the operation, as if nothing had happened; which is a little more complicated; you will need to keep track of what data was successfully written to disk so that after you notify the user and indicate that it is time to try again, you can resume recording this data from the place where the error occurred. This means saving the state of the record in some structure (i.e., not only on the stack) so that you can return from your recording function and then resume it later. (Either this, or record in a separate thread, and ask the thread to inform the main thread, and then block until the main thread notifies you that it is safe to continue ... it can be a bit complicated, though)
source share