1 | /* |
---|
2 | * This is a shared BSP post driver hook designed to open |
---|
3 | * /dev/console for stdin, stdout, and stderr if it exists. |
---|
4 | * Newlib will automatically associate the file descriptors |
---|
5 | * with the first thress files opened. |
---|
6 | * |
---|
7 | * COPYRIGHT (c) 1989-2007. |
---|
8 | * On-Line Applications Research Corporation (OAR). |
---|
9 | * |
---|
10 | * The license and distribution terms for this file may be |
---|
11 | * found in the file LICENSE in this distribution or at |
---|
12 | * http://www.rtems.com/license/LICENSE. |
---|
13 | * |
---|
14 | * $Id$ |
---|
15 | */ |
---|
16 | |
---|
17 | #include <rtems.h> |
---|
18 | #include <rtems/libio.h> |
---|
19 | #include <fcntl.h> |
---|
20 | |
---|
21 | void bsp_postdriver_hook(void) |
---|
22 | { |
---|
23 | int stdin_fd, stdout_fd, stderr_fd; |
---|
24 | int error_code = 'S' << 24 | 'T' << 16 | 'D' << 8; |
---|
25 | |
---|
26 | /* |
---|
27 | * Attempt to open /dev/console. |
---|
28 | */ |
---|
29 | if ((stdin_fd = open("/dev/console", O_RDONLY, 0)) == -1) { |
---|
30 | /* |
---|
31 | * There may not be a console driver so this is OK. |
---|
32 | */ |
---|
33 | return; |
---|
34 | } |
---|
35 | |
---|
36 | /* |
---|
37 | * But if we find /dev/console once, we better find it twice more |
---|
38 | * or something is REALLY wrong. |
---|
39 | */ |
---|
40 | if ((stdout_fd = open("/dev/console", O_WRONLY, 0)) == -1) |
---|
41 | rtems_fatal_error_occurred( error_code | '1' ); |
---|
42 | |
---|
43 | if ((stderr_fd = open("/dev/console", O_WRONLY, 0)) == -1) |
---|
44 | rtems_fatal_error_occurred( error_code | '2' ); |
---|
45 | } |
---|