How to find out if the maximum file size was reached when using a stream?

When recording a file using a stream, how do you know when the file size reached the maximum OS file size - more specifically, the maximum linux file size - ??

+3
source share
4 answers

First, the maximum file size is the limit of the file system, not the limit of the operating system. It will even change for a specific file system based on how the file system was formatted.

As for how you realize that you have reached the limit, your code will most likely throw an exception when this happens, and you can return to the OS error codes.

, darn "" EXT2 - . , , . , , , , .

+5

, . , exceptions, , .

+4

( 100%), , OS max. , , OS io .

0

Well, fstream does not have an exceptional exception for “writing to a file that exceeds the maximum file size for implementation” (from “man 2 write”), for example, the EFBIG error code available when using the C function 'write'. So, I think what needs to be done, as Jim Franton said, and compare the file size with the user-defined maximum size or with the maximum value held by the variable "streamoff", which is the type of variable used to handle file sizes - file offset is actually - in iostream.

0
source

Source: https://habr.com/ru/post/1697522/


All Articles