Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ftruncate is missing from core::libc #4199

Closed
Dretch opened this issue Dec 15, 2012 · 9 comments
Closed

ftruncate is missing from core::libc #4199

Dretch opened this issue Dec 15, 2012 · 9 comments

Comments

@Dretch
Copy link
Contributor

Dretch commented Dec 15, 2012

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.

@brson
Copy link
Contributor

brson commented 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
Copy link
Contributor Author

Dretch commented 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
Copy link
Contributor Author

Dretch commented 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
Copy link
Contributor

@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 for ftruncate64 confirms that it's just a leftover legacy function.

@Aatch
Copy link
Contributor

Aatch commented 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.

@Aatch Aatch closed this as completed Jun 7, 2013
@thestinger
Copy link
Contributor

@Aatch: ftruncate is for truncating files :)

@thestinger thestinger reopened this Jun 7, 2013
@msullivan
Copy link
Contributor

Still isn't implemented. Are we decided this is something we want? Does windows support it? Should this actually be milestoned?

@thestinger
Copy link
Contributor

Still not implemented.

@Dretch
Copy link
Contributor Author

Dretch commented Jan 1, 2014

It looks like this is now implemented in std::io::fs, thanks!

@Dretch Dretch closed this as completed Jan 1, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants