free disk space

C

Christopher Benson-Manica

Piotr said:
What is the simple function checking free disk space ?

There isn't one in standard C. If you're using Unix, the du and/or quota
commands may be useful to you.
 
N

Nils Petter Vaskinn

There isn't one in standard C.

open a file,
write to the file until you get an error, counting bytes
close and reopen the file to free the space
close the file

Now the filesystem should have atleast as much free space as the bytes you
counted.

But he'd probably be better of using a platform specific way :)
 
D

Dan Pop

In said:
What is the simple function checking free disk space ?

No such thing. The C language blissfully ignores the existence of disks
(although it realises that some devices are seekable and others aren't).

Dan
 
M

Mark Gordon

open a file,
write to the file until you get an error, counting bytes
close and reopen the file to free the space
close the file

Now the filesystem should have atleast as much free space as the bytes
you counted.

But he'd probably be better of using a platform specific way :)

What you suggested IS a platform specific way. If you try it on a file
system with file versioning when you reopen the file it might just
create a new version of the file leaving the old on on the disk. If you
use a temporary file instead, it might be held in memory and therefor
report free space even if the disk is full.
 
N

Nils Petter Vaskinn

What you suggested IS a platform specific way. If you try it on a file
system with file versioning when you reopen the file it might just
create a new version of the file leaving the old on on the disk.
Ouch

If you
use a temporary file instead, it might be held in memory and therefor
report free space even if the disk is full.

Well I wasn't exactly beeing serious, so I didn't try to think about
everything.
 
K

Kelsey Bjarnason

open a file,
write to the file until you get an error, counting bytes
close and reopen the file to free the space
close the file

Now the filesystem should have atleast as much free space as the bytes you
counted.

But he'd probably be better of using a platform specific way :)

I can just picture doing this on a system with a large storage array...
say one of those nifty 43TB units. A week or two later and he finally has
his value... :)
 
P

Peter Pichler

Mark Gordon said:
What you suggested IS a platform specific way. If you try it on a file
system with file versioning when you reopen the file it might just
create a new version of the file leaving the old on on the disk. If you
use a temporary file instead, it might be held in memory and therefor
report free space even if the disk is full.

Not to mention file systems with limited file sizes, where the available
disk space may be significantly greater than a file you would create
using that method. At least the "at least" would apply in such a case :)

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,187
Latest member
RosaDemko

Latest Threads

Top