1

I'm making a program and one of the things it needs to do is transfer files. I would like to be able to check before I start moving files if the File system supports files of size X. What is the best way of going about this?

1
  • Roughly, what's the largest value of X you're potentially expecting?
    – NPE
    Oct 9, 2011 at 9:28

2 Answers 2

2

Go on with using a function like ftruncate to create a file of the desired size in advance, before the moving, and do the appropriate error-handling in case it fails.

1
  • It should be noted that being able to create a file of size X using ftruncate doesn't necessarily mean that file may also exist once filled with data (as some filesystems allow sparse files, with empty blocks usually taking no space. there may not be enough free space for a non-sparse file)
    – Hasturkun
    Oct 9, 2011 at 9:57
2

There's no C standard generic API for this. You could simply try creating a file and writing junk to it until it is the size you want, then deleting it, but even that isn't guaranteed to give you the info you need - for instance another process might have come and written a large file in between your test and your transfer, taking up space you were hoping to use.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.