Re: Accessing the file descriptor for an fstream (gcc3-)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Vitaly,

>Hmm.... what about making fd -> stdin, stdout, stderr?

For C, the stdin, stdout, stderr identifiers are not file descriptors, they are FILE*.

In POSIX, one can do this to get the file descriptor...
    int fd_stdin = fileno(stdin);
...but "fileno" is POSIX-compliant, but not necessarily portable as it is not part of the C standard (ala X3.159-1989 --> ISO 9899:1989).  In the C standard, I don't think there is a way to extract the file descriptor from the FILE*... because not all OS's use file descriptors, so it wouldn't be portable.  (I presume that all POSIX compliant systems use file descriptors, even if the compiler has to do some magic to map the file descriptor to the underlying OS facility, such as a resource handle.)

In C++, stdin, stdout, and stderr are C legacy items.  The preferred and recommended mechanisms are std::cin, std::cout, and std::cerr.

Sincerely,
--Eljay

PS:  "Vitaly" ... cool name!



[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux