<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">The document at <a href="http://pubs.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html">http://pubs.opengroup.org/onlinepubs/009695399/basedefs/unistd.h.html</a> implies that they really are supposed to be constants:<div><span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; "><br></span></div><div><span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; ">The following symbolic constants shall be defined for file streams:</span></div><div><span class="Apple-style-span" style="font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 13px; "><dl compact=""><dt>STDERR_FILENO</dt><dd>File number of <i>stderr</i>; 2.</dd><dt>STDIN_FILENO</dt><dd>File number of <i>stdin</i>; 0.</dd><dt>STDOUT_FILENO</dt><dd>File number of <i>stdout</i>; 1.</dd></dl></span><div><br></div><div>but I agree that that is rather counterintuitive.</div><div><br></div><div><div>On Mar 11, 2011, at 12:21 PM, Peter Dufault wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div>Shouldn't STDOUT_FILENO etc always be valid, regardless of thread?<br><br>Consider this code snippet installed in the RTEMS shell as "filenos":<br>===<br>static int<br>filenos_cmd(int argc, char **argv)<br>{<br> int stdin_fileno = fileno(stdin),<br> stdout_fileno = fileno(stdout),<br> stderr_fileno = fileno(stderr);<br><br> fprintf(stderr,<br> "fileno(stdin), STDIN_FILENO: %d %d\n"<br> "fileno(stdout), STDOUT_FILENO: %d %d\n"<br> "fileno(stderr), STDERR_FILENO: %d %d\n",<br> stdin_fileno, STDIN_FILENO,<br> stdout_fileno, STDOUT_FILENO,<br> stderr_fileno, STDERR_FILENO);<br><br> fprintf(stderr, "- %s\n",<br> (stdin_fileno == STDIN_FILENO &&<br> stdout_fileno == STDOUT_FILENO &&<br> stderr_fileno == STDERR_FILENO) ? "OK" : "BAD");<br><br> return 0;<br>}<br>====<br><br>Called from the console:<br><br>[/] # filenos <br>fileno(stdin), STDIN_FILENO: 0 0 <br>fileno(stdout), STDOUT_FILENO: 1 1 <br>fileno(stderr), STDERR_FILENO: 2 2 <br>- OK <br>[/] # <br><br>Called via telnet:<br><br>[/] # filenos<br>fileno(stdin), STDIN_FILENO: 7 0<br>fileno(stdout), STDOUT_FILENO: 8 1<br>fileno(stderr), STDERR_FILENO: 9 2<br>- BAD<br>[/] # <br><br>Shouldn't the macros reference something that changes with the thread context to appropriate file descriptors without forcing reference to <stdio.h>?<br><br>Peter<br>-----------------<br>Peter Dufault<br>HD Associates, Inc. Software and System Engineering<br><br><br>_______________________________________________<br>rtems-users mailing list<br><a href="mailto:rtems-users@rtems.org">rtems-users@rtems.org</a><br>http://www.rtems.org/mailman/listinfo/rtems-users<br></div></blockquote></div><br><div>
<span class="Apple-style-span" style="border-collapse: separate; color: rgb(0, 0, 0); font-family: Helvetica; font-size: medium; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-align: auto; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; "><div>-- <br>Eric Norum<br><a href="mailto:wenorum@lbl.gov">wenorum@lbl.gov</a></div></span>
</div>
<br></div></body></html>