Boost logo

Boost Users :

Subject: Re: [Boost-users] [filesystem] how to set a file size?
From: Beman Dawes (bdawes_at_[hidden])
Date: 2009-10-14 09:22:49


On Tue, Oct 13, 2009 at 3:26 PM, Eric Niebler <eric_at_[hidden]> wrote:

> Roland Bock wrote:
>
>> Eric Niebler wrote:
>>
>>>
>>> Forgive me for the n00b-ish (and slightly offtopic) question, but is
>>> there any way in standard C++ or in Boost.Filesystem to truncate a file to a
>>> particular size? With std::ofstream, I can either truncate a file on open to
>>> 0 size, or else open it in overwrite mode and scribble over it, but when I'm
>>> done, I don't seem to have a way of saying, "The end of the file is now
>>> *here*." Is that right? And if so, does Boost.Filesystem have an API for
>>> this?
>>>
>>
>> There are two posix functions ("truncate" and "ftruncate") which might do
>> what you need.
>>
>
> It doesn't look like these functions exist for MSVC users. So it seems
> there is no portable way to change the size of a file. Beman, would this
> make a good addition to the filesystem library?
>

Yes, a truncate function would be a nice addition.

It looks doable. I'll look into it further.

Thanks,

--Beman



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net