I’m writing a C++ program which will be printing out large (2-4GB) files.
I’d like to make sure that there’s sufficient space on the drive to save the files before I start writing them. If possible, I’d like to reserve this space.
This is taking place on a Linux-based system.
Any thoughts on a good way to do this?
Take a look at
posix_fallocate():edit In the comments you indicate that you use C++ streams to write to the file. As far as I know, there’s no standard way to get the file descriptor (
fd) from astd::fstream.With this in mind, I would make disk space pre-allocation a separate step in the process. It would:
open()the file;posix_fallocate();close()the file.This can be turned into a short function to be called before you even open the
fstream.