| 116 | } |
| 117 | |
| 118 | static int free_file_descriptor(int fileno) |
| 119 | { |
| 120 | FAT_FILE *stream; |
| 121 | FIL *fh; |
| 122 | |
| 123 | if (isatty_( fileno )) { |
| 124 | errno = EBADF; |
| 125 | return -1; |
| 126 | } |
| 127 | |
| 128 | // checks if fileno out of bounds |
| 129 | stream = fileno_to_stream(fileno); |
| 130 | if (stream == nullptr) { |
| 131 | return -1; |
| 132 | } |
| 133 | |
| 134 | fh = stream->fh; |
| 135 | |
| 136 | if (fh != NULL) { |
| 137 | free(fh); |
| 138 | } |
| 139 | |
| 140 | free(stream->name); |
| 141 | stream->name = NULL; |
| 142 | |
| 143 | file_table[fileno] = NULL; |
| 144 | free(stream); |
| 145 | return fileno; |
| 146 | } |
| 147 | |
| 148 | static FIL *fileno_to_fatfs(int fileno) |
| 149 | { |
no test coverage detected