| 3432 | #define stderr (*stdio_get_stream(STDERR_FILENO)) |
| 3433 | |
| 3434 | static __attribute__((__noinline__, __const__)) FILE **stdio_get_stream(int fd) |
| 3435 | { |
| 3436 | if (fd != STDIN_FILENO && fd != STDOUT_FILENO && fd != STDERR_FILENO) |
| 3437 | return NULL; |
| 3438 | |
| 3439 | if (stdio_stream[fd] != NULL) |
| 3440 | return &stdio_stream[fd]; |
| 3441 | |
| 3442 | bool r = (fd == STDIN_FILENO); |
| 3443 | bool w = (fd == STDOUT_FILENO || fd == STDERR_FILENO); |
| 3444 | int mode = (fd == STDERR_FILENO? _IONBF: _IOLBF); |
| 3445 | if (mutex_lock(&stdio_mutex) < 0) |
| 3446 | panic("failed to lock stdio stream"); |
| 3447 | if (stdio_stream[fd] == NULL) |
| 3448 | { |
| 3449 | FILE *stream = stdio_stream_alloc(fd, r, w, mode); |
| 3450 | if (stream == NULL) |
| 3451 | panic("failed to allocate stdio stream"); |
| 3452 | stdio_stream[fd] = stream; |
| 3453 | } |
| 3454 | mutex_unlock(&stdio_mutex); |
| 3455 | |
| 3456 | return &stdio_stream[fd]; |
| 3457 | } |
| 3458 | |
| 3459 | static int fputc_unlocked(int c, FILE *stream) |
| 3460 | { |
nothing calls this directly
no test coverage detected