How can I get a file descriptor from a c++ i/o stream?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Thorsten Knopel

    How can I get a file descriptor from a c++ i/o stream?

    Dear all,

    Because of some reason, I must get a file descript from a c++ I/O stream,
    for example: ifstream.

    Under OpenUnix I have a function ifstream::fd (rdbuf->fd) to do this.
    But in Linux, there is not a such function of ifstream class.
    Is there not a such function in standard C++ ?
    Or is there another way to get?

    Thanks for your help.
    Regards,
    Thorsten

  • Victor Bazarov

    #2
    Re: How can I get a file descriptor from a c++ i/o stream?

    Thorsten Knopel wrote:[color=blue]
    > Because of some reason, I must get a file descript from a c++ I/O stream,
    > for example: ifstream.
    >
    > Under OpenUnix I have a function ifstream::fd (rdbuf->fd) to do this.
    > But in Linux, there is not a such function of ifstream class.
    > Is there not a such function in standard C++ ?[/color]

    No. In general a stream doesn't have to have anything like a "file
    descriptor" in it. It's implementation-defined how streams maintain
    their association with whatever is considered "a file".
    [color=blue]
    > Or is there another way to get?[/color]

    There can be something specific to your library implementation. Have
    you tried looking in the docs or asking in a newsgroup for your OS?

    V

    Comment

    • Pete Becker

      #3
      Re: How can I get a file descriptor from a c++ i/o stream?

      Victor Bazarov wrote:[color=blue]
      > It's implementation-defined how streams maintain
      > their association with whatever is considered "a file".
      >[/color]

      It's unspecified, not implementation defined. The implementation doesn't
      have to document what it does.

      --

      Pete Becker
      Dinkumware, Ltd. (http://www.dinkumware.com)

      Comment

      Working...