/* * Copyright (C) 2020 Embecosm Limited * SPDX-License-Identifier: BSD-2-Clause */ #include "semihost_fdtable.h" #include #include #include #ifndef RISCV_MAX_OPEN_FILES #define RISCV_MAX_OPEN_FILES 16 #endif extern int errno; extern int _open (const char *, int, ...); /* fdtable keeps track of the position of each file and is used to map stdin, stdout and stderr to STDIN_FILENO, STDOUT_FILENO and STDERR_FILENO. */ static struct fdentry fdtable[RISCV_MAX_OPEN_FILES]; /* Initialize fdtable. A handle of -1 denotes an empty entry. */ void __attribute__ ((constructor)) init_semihosting () { int i; for (i=0; i=RISCV_MAX_OPEN_FILES || fdtable[file].handle == -1) { errno = EBADF; return NULL; } return &fdtable[file]; } /* Remove entry from fdtable. */ void __remove_fdentry (int file) { fdtable[file].handle = -1; }