fstat for an open fstream

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Klaus Füller

    fstat for an open fstream

    I would like to use the unix,et.al-fstat() system-call on some sort of
    stream which is already open and connected to a disk file.

    An example: I have an open stream and want to know the numerical
    owner-id of the file associated with the stream.

    I can write the code myself if someone tells me how to get the
    filedescriptor that must be buried as a member attribute somewhere in
    the stream-classes. Eventually all io must pass through such a
    descriptor - so it _must_ exist somewhere.

    I know how to retrieve the information if I have the filename (call
    stat()) --- but I want to use fstat() on an already open stream.

    Any glue?

    Klaus.

  • WW

    #2
    Re: fstat for an open fstream

    Klaus Füller wrote:[color=blue]
    > I would like to use the unix,et.al-fstat() system-call on some sort of
    > stream which is already open and connected to a disk file.[/color]
    [SNIP][color=blue]
    > Any glue?[/color]

    Yep. Stick with a UNIX/Posix newsgroup :-)





    --
    WW aka Attila


    Comment

    • Klaus Füller

      #3
      Re: fstat for an open fstream

      WW schrieb:[color=blue]
      > Klaus Füller wrote:
      > [color=green]
      >>I would like to use the unix,et.al-fstat() system-call on some sort of
      >>stream which is already open and connected to a disk file.[/color]
      >
      > [SNIP]
      > [color=green]
      >>Any glue?[/color]
      >
      >
      > Yep. Stick with a UNIX/Posix newsgroup :-)[/color]
      Thank you.

      I know how to do it in Unix and Posix but I don't know how to do it in
      C++. Although I'm aware about the fact that the information I want to
      get is not fully portable there must - or at least should - be a
      portable way to get some of this.

      So - sorry - I insist that this is the right place to ask for it.

      The general question is - how do I get the underlying filedescriptor of
      a stream - no matter what OS the program runs on and no matter how
      opaque the returnde information might be.

      Comment

      • WW

        #4
        Re: fstat for an open fstream

        Klaus Füller wrote:[color=blue]
        > WW schrieb:[color=green]
        >> Klaus Füller wrote:
        >>[color=darkred]
        >>> I would like to use the unix,et.al-fstat() system-call on some sort
        >>> of stream which is already open and connected to a disk file.[/color]
        >>
        >> [SNIP]
        >>[color=darkred]
        >>> Any glue?[/color]
        >>
        >>
        >> Yep. Stick with a UNIX/Posix newsgroup :-)[/color]
        > Thank you.
        >
        > I know how to do it in Unix and Posix but I don't know how to do it in
        > C++. Although I'm aware about the fact that the information I want to
        > get is not fully portable there must - or at least should - be a
        > portable way to get some of this.
        >
        > So - sorry - I insist that this is the right place to ask for it.
        >
        > The general question is - how do I get the underlying filedescriptor
        > of a stream - no matter what OS the program runs on and no matter how
        > opaque the returnde information might be.[/color]

        This newsgroup discusses *only* the standard C++ language. So please don't
        insist(*), but go to the group/discussion forum/technical support of your
        compiler/standard library implementation and ask it there.

        (*) Here the answer is: you cannot do it. Only the pre-standard iostreams
        had support to retrieve their file descriptor. The standard iostreams do
        not support it. And any non-standard feature discussion should go to the
        implementation specific discussion forums.

        --
        WW aka Attila


        Comment

        • Mike Wahler

          #5
          Re: [OT] fstat for an open fstream

          "Klaus Füller" <klausf@schule. de> wrote in message
          news:3F745F91.4 020605@schule.d e...
          WW schrieb:[color=blue]
          > Klaus Füller wrote:
          >[color=green]
          >>I would like to use the unix,et.al-fstat() system-call on some sort of
          >>stream which is already open and connected to a disk file.[/color]
          >
          > [SNIP]
          >[color=green]
          >>Any glue?[/color]
          >
          >
          > Yep. Stick with a UNIX/Posix newsgroup :-)[/color]
          Thank you.
          [color=blue]
          >I know how to do it in Unix and Posix but I don't know how to do it in
          >C++.[/color]

          It cannot be done with C++ alone. Many C++ implementations
          do provide POSIX support as an 'extension', so that's a possible route.
          [color=blue]
          > Although I'm aware about the fact that the information I want to
          > get is not fully portable[/color]

          It's not portable at all from a C++ perspective.
          [color=blue]
          >there must - or at least should - be a
          > portable way to get some of this.[/color]

          Say 'should' if you like, but there is no portable way.
          It "shouldn't" rain anytime I go outside, but
          soemtimes it does. :-)
          [color=blue]
          > So - sorry - I insist that this is the right place to ask for it.[/color]

          Insist all you like, but it's not. Only ISO standard C++
          is the topic here, which cannot do what you ask. Haven't
          you read the welcome message at the link that "WW" provided?
          It states very clearly what is and is not topical here.
          [color=blue]
          >The general question is - how do I get the underlying filedescriptor of
          >a stream - no matter what OS the program runs on[/color]

          You cannot. The form and usage of 'file descriptors'
          (if even used) are necessarily dependent upon the
          implementation, and by implication, the host OS.
          C++ has no concept at all of 'file descriptor'.

          E.g. UNIX and VMS don't handle files the same way.
          But at the 'higher level' of C++ code, they can
          be accessed in a uniform way by using the iostream
          abstraction.

          I suppose you could dig around in your implementation' s
          internals and figure it out, but the method you come up
          with will only be valid for that implementation (might
          also be for other implementations on the same platform,
          but not necessarily.)
          [color=blue]
          >and no matter how >
          >opaque the returnde information might be.[/color]

          'Opaqueness' is already provided by the iostreams
          abstraction.

          You're talking about a necessarily platform-dependent
          issue. So if you want portability, you'll need to
          write a module for each platform, and adjust compilation
          accordingly for each.

          -Mike




          Comment

          Working...