[rtems commit] libio: Ensure proper std file descriptors

Sebastian Huber sebh at rtems.org
Mon Dec 12 07:05:52 UTC 2016


Module:    rtems
Branch:    master
Commit:    af8ced5e2d8fb8552f29a1bad5a32a72b939adc7
Changeset: http://git.rtems.org/rtems/commit/?id=af8ced5e2d8fb8552f29a1bad5a32a72b939adc7

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Fri Dec  9 09:18:57 2016 +0100

libio: Ensure proper std file descriptors

---

 cpukit/libcsupport/src/open_dev_console.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/cpukit/libcsupport/src/open_dev_console.c b/cpukit/libcsupport/src/open_dev_console.c
index 2e111cc..14257e8 100644
--- a/cpukit/libcsupport/src/open_dev_console.c
+++ b/cpukit/libcsupport/src/open_dev_console.c
@@ -17,20 +17,17 @@
 #include <rtems/libio.h>
 #include <fcntl.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 /*
  *  This is a replaceable stub which opens the console, if present.
  */
 void rtems_libio_post_driver(void)
 {
-  int      stdin_fd;
-  int      stdout_fd;
-  int      stderr_fd;
-
   /*
    * Attempt to open /dev/console.
    */
-  if ((stdin_fd = open("/dev/console", O_RDONLY, 0)) == -1) {
+  if (open("/dev/console", O_RDONLY, 0) != STDIN_FILENO) {
     /*
      * There may not be a console driver so this is OK.
      */
@@ -41,11 +38,13 @@ void rtems_libio_post_driver(void)
    *  But if we find /dev/console once, we better find it twice more
    *  or something is REALLY wrong.
    */
-  if ((stdout_fd = open("/dev/console", O_WRONLY, 0)) == -1)
-    rtems_fatal_error_occurred( 0x55544431 );  /* error STD1 */
+  if (open("/dev/console", O_WRONLY, 0) != STDOUT_FILENO) {
+    rtems_fatal_error_occurred( 0x55544431 );
+  }
 
-  if ((stderr_fd = open("/dev/console", O_WRONLY, 0)) == -1)
-    rtems_fatal_error_occurred( 0x55544432 );  /* error STD2 */
+  if (open("/dev/console", O_WRONLY, 0) != STDERR_FILENO) {
+    rtems_fatal_error_occurred( 0x55544432 );
+  }
 
   atexit(rtems_libio_exit);
 }




More information about the vc mailing list