Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I know I reached a file's maximum size when using ofstream?

Tags:

c++

linux

While writing a file using ofstream, how do I know when the file's size has reached the OS' maximum file size - more specifically linux's maximum file size - ??

like image 393
Salsa Avatar asked Nov 04 '25 14:11

Salsa


1 Answers

First off, maximum file size is a filesystem limit, not an Operating System limit. It will even vary for a particular filesystem, based on how the filesystem was formatted.

As for how you'd figure out that you'd reached the limit, your code will likely throw an exception when that happens, which you'll then be able to relate back to the OS error codes.

Note that the actual limit is pretty darn big for a "typical" EXT2 filesystem - in the Terabytes. You'll likely never reach it, in practice. If you seriously are accumulating Terabytes of data, you might want to consider whether there's a more reasonable way to store it, rather than a single gigantic file.

like image 155
Mark Bessey Avatar answered Nov 07 '25 09:11

Mark Bessey