Skip to content

Commit d6e040e

Browse files
committed
get internal handles in reverse order so as to avoid conflict with BASIC hardcoded handles
1 parent 3dda4f1 commit d6e040e

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

include/libc/unix/posixio.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,10 +243,17 @@ int _find_free_file()
243243
}
244244

245245
/* get a new vfs file handle */
246+
/* only used internally, and prefers bigger handles
247+
so as not to conflict with BASIC hardcoded integers
248+
*/
249+
246250
vfs_file_t *
247251
_get_vfs_file_handle()
248252
{
249-
int fd = _find_free_file();
253+
int fd;
254+
for (fd = _MAX_FILES-1; fd >= 0; --fd) {
255+
if (__filetab[fd].state == 0) break;
256+
}
250257
if (fd < 0) return 0;
251258
return &__filetab[fd];
252259
}

0 commit comments

Comments
 (0)