
On Fri, 10 Sep 2010 07:26:06 -0400 "Stewart, Robert" <Robert.Stewart@sig.com> wrote:
Jeremy Maitin-Shepard wrote:
[snip] context::map_file_descriptor(int child_fileno, file_descriptor_t existing_descriptor);
Potentially this same interface could be used on Windows, with child_fileno only valid in the range 0 to 2 (and with appropriate constants defined), and could thus serve as the lowest level interface on top of which other behaviors like pipe, redirect, etc. could be implemented.
The problem with the suggested approach is that Windows winds up with runtime errors if the child_fileno argument exceeds the range. It would be better to make that a compile time error. The only way to do that is to use a template with the fileno being a template argument.
enum std_fileno { stdin, stdout, stderr } #ifdef _WIN32 typedef std_fileno fileno; #else typedef int fileno; #endif void foo(fileno); foo(stdout) // ok foo(1) // ok on posix, compile error on windows