MCPcopy Create free account
hub / github.com/GJDuck/e9patch / stdio_get_stream

Function stdio_get_stream

examples/stdlib.c:3434–3457  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3432#define stderr (*stdio_get_stream(STDERR_FILENO))
3433
3434static __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
3459static int fputc_unlocked(int c, FILE *stream)
3460{

Callers

nothing calls this directly

Calls 3

mutex_lockFunction · 0.85
stdio_stream_allocFunction · 0.85
mutex_unlockFunction · 0.85

Tested by

no test coverage detected