Code Monkey home page Code Monkey logo

Comments (3)

Urgau avatar Urgau commented on June 6, 2024

It may be silly but rustix could be cleaver and just have one API:

pub fn dup<Fd: AsFd>(fd: Fd, into: Option<&OwnedFd>, flags: DupFlags) -> Result<()>

This would handle the 4 functions at once:

With the sale behavior of dup3 if the two file descriptor are equal.

from rustix.

cgwalters avatar cgwalters commented on June 6, 2024

What would be in DupFlags? I think fnctl_dupfd_cloexec really wants to take a RawFd and not an Option<&OwnedFd> for the lower bound for example.

It seems hard to avoid some...duplication here; I think I'd lean more towards having the API match the Linux system calls, and just ensuring the documentation makes things clear.

from rustix.

sunfishcode avatar sunfishcode commented on June 6, 2024

I'm leaning that way too. These functions are all superficially similar, but they have different use cases: "I want a copy of this fd with an independent lifetime" vs. "I want to overwrite this existing fd with something else". We'll eventually have different documentation for these different use cases. It's also nice if we can avoid having applications transitively depend on system calls they aren't using, where feasible.

FreeBSD also has a dup3 which follows the Linux behavior. So I'm leaning towards just renaming rustix's dup2_with to dup3 and just documenting that. Rustix sometimes tries to present things in more intuitive ways, but in this case, there are enough variations with enough subtle behavioral differences that there's a risk we'd just make it even more confusing if we tried to simplify.

from rustix.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.