Skip to content

ftruncate is missing from core::libc #4199

Closed
@Dretch

Description

@Dretch
Contributor

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

brson commented on Dec 17, 2012

@brson
Contributor

@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

Dretch commented on Dec 23, 2012

@Dretch
ContributorAuthor

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

Dretch commented on Dec 23, 2012

@Dretch
ContributorAuthor

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

thestinger commented on Dec 31, 2012

@thestinger
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

Aatch commented on Jun 7, 2013

@Aatch
Contributor

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

thestinger commented on Jun 7, 2013

@thestinger
Contributor

@Aatch: ftruncate is for truncating files :)

msullivan

msullivan commented on Jul 25, 2013

@msullivan
Contributor

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

thestinger

thestinger commented on Sep 30, 2013

@thestinger
Contributor

Still not implemented.

Dretch

Dretch commented on Jan 1, 2014

@Dretch
ContributorAuthor

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

added 2 commits that reference this issue on Feb 24, 2025
d15e00e
13ff65e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @brson@msullivan@Aatch@Dretch@thestinger

        Issue actions

          ftruncate is missing from core::libc · Issue #4199 · rust-lang/rust