//----------------------------------------------------------------------------- // _check_file_open: Returns true if the file is already open //----------------------------------------------------------------------------- static int _check_file_open(FL_FILE file) { FL_FILE openFile = Filelib_open_files; // Compare open files while (openFile != null) { // If not the current file if (openFile != file) { // Compare path and name if ((fatfs_compare_names(openFile.path, file.path)) && (fatfs_compare_names(openFile.filename, file.filename))) return 1; } openFile = openFile.next; } return 0; }
//----------------------------------------------------------------------------- // _free_file: Free open file handle //----------------------------------------------------------------------------- static void _free_file(FL_FILE file) { FL_FILE openFile = Filelib_open_files; FL_FILE lastFile = null; // Remove from open list while (openFile != null) { // If the current file if (openFile == file) { if (lastFile) lastFile.next = openFile.next; else Filelib_open_files = openFile.next; break; } lastFile = openFile; openFile = openFile.next; } // Add to free list file.next = Filelib_free_files; Filelib_free_files = file; }
//----------------------------------------------------------------------------- // _allocate_file: Find a slot in the open files buffer for a new file //----------------------------------------------------------------------------- static FL_FILE _allocate_file() { // Allocate free file FL_FILE file = Filelib_free_files; if (file != null) { Filelib_free_files = file.next; // Add to open list file.next = Filelib_open_files; Filelib_open_files = file; } return file; }