This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]