I wrote a C++ application on linux using cstdio. It contains one function which should overwrite a whole device with random data. It is given a file name, creates blocks of random data in memory and writes them one after the other using fwrite() to the file.
If the device is full, the function should return. If there is a different write error, it should throw an exception.
So when an error occurs I ask ferror() and want to recognize if this is a “disk is full” – a different error.
I would expect to get ENOSPC when the disk is full. But the function writes to the disk and when it’s full, the value returned by ferror() is 1 (which is EPERM).
perror on the other hand prints the correct “No space left on device”.
Is this a bug in my C++ libs? Or is EPERM the correct error code?
If it is the correct error code, is EPERM only returned when the disk is full and therefore suitable for recognizing this specific error?
I wrote a C++ application on linux using cstdio. It contains one function which
Share
ferroronly tells you whether there was an error on the stream. To see what the error actually was, you have to examineerrno.perrorexamineserrnowhich is why it prints the correct error message.