Closed
Description
rust does not seem to have the ftruncate function (http://pubs.opengroup.org/onlinepubs/7908799/xsh/ftruncate.html).
Might it be possible to add such a function? Some trickery would be needed on windows, like using _chsize instead (http://msdn.microsoft.com/en-us/library/dk925tyb%28v=vs.80%29.aspx).
Is there any reason this function shouldn't exist? If not then I will try and submit a pull request.
Activity
brson commentedon Dec 17, 2012
@graydon knows best.
Personally I think if the function doesn't exist on windows we should not try to emulate it in
core::libc
, but at a higher-level API.Dretch commentedon Dec 23, 2012
It seems that actually ftruncate is available on windows, using mingw.
So I think just adding a ftruncate binding should work, but that will break when rust abandons mingw in favour of msvc (#1768). Is that desirable (i guess not)?
Dretch commentedon Dec 23, 2012
I think that ideally the cross-platform ftruncate would use ftruncate64 on linux, ftruncate on OS X (which doesn't have ftruncate64, but instead always has a 64-bit off_t so ftruncate always takes a 64 bit length) and _chsize_s on windows (which also takes a 64bit length).
Unfortunately mingw does not have either ftruncate64 or _chsize_s.
thestinger commentedon Dec 31, 2012
@Dretch: There's no need to use
ftruncate64
on Linux, as long as_FILE_OFFSET_BITS=64
is used on 32-bit (and it should be anyway for functions like stat). The man page forftruncate64
confirms that it's just a leftover legacy function.Aatch commentedon Jun 7, 2013
There is no need for this, we have a trunc method implemented on floats that uses trunc[f] from libm.
There is also a push to remove dependency on cmath/libm so I'm closing this.
thestinger commentedon Jun 7, 2013
@Aatch: ftruncate is for truncating files :)
msullivan commentedon Jul 25, 2013
Still isn't implemented. Are we decided this is something we want? Does windows support it? Should this actually be milestoned?
thestinger commentedon Sep 30, 2013
Still not implemented.
Dretch commentedon Jan 1, 2014
It looks like this is now implemented in
std::io::fs
, thanks!Merge pull request rust-lang#4199 from tiif/small_fix
Merge pull request rust-lang#4199 from tiif/small_fix