int check_mark_directory(FileView *view, char m) { const mark_t *const mark = get_mark_by_name(m); if(is_empty(mark)) { return -1; } if(flist_custom_active(view)) { dir_entry_t *entry; char path[PATH_MAX]; snprintf(path, sizeof(path), "%s/%s", mark->directory, mark->file); entry = entry_from_path(view->dir_entry, view->list_rows, path); if(entry != NULL) { return entry_to_pos(view, entry); } } else if(paths_are_equal(view->curr_dir, mark->directory)) { return find_file_pos_in_list(view, mark->file); } return -1; }
static int _OTP_stat_r(struct _reent *r, const char *path, struct stat *st) { DIR_ENTRY *entry = entry_from_path(path); if (!entry) { r->_errno = ENOENT; return -1; } stat_entry(entry, st); return 0; }
static int _OTP_chdir_r(struct _reent *r, const char *path) { DIR_ENTRY *entry = entry_from_path(path); if (!entry) { r->_errno = ENOENT; return -1; } else if (entry != &entries[0]) { r->_errno = ENOTDIR; return -1; } return 0; }
static DIR_ITER *_OTP_diropen_r(struct _reent *r, DIR_ITER *dirState, const char *path) { DIR_STATE_STRUCT *state = (DIR_STATE_STRUCT *)(dirState->dirStruct); state->entry = entry_from_path(path); if (!state->entry) { r->_errno = ENOENT; return NULL; } else if (state->entry != &entries[0]) { r->_errno = ENOTDIR; return NULL; } state->index = 1; state->inUse = true; return dirState; }
static int _OTP_open_r(struct _reent *r, void *fileStruct, const char *path, int flags, int mode) { FILE_STRUCT *file = (FILE_STRUCT *)fileStruct; DIR_ENTRY *entry = entry_from_path(path); if (!entry) { r->_errno = ENOENT; return -1; } else if (entry == &entries[0]) { r->_errno = EISDIR; return -1; } file->entry = entry; file->offset = 0; file->inUse = true; return (int)file; }
/* Loads full list of files into unfiltered list of the view. Returns position * of file under cursor in the unfiltered list. */ static int load_unfiltered_list(view_t *view) { int current_file_pos = view->list_pos; view->local_filter.in_progress = 1; view->local_filter.saved = strdup(view->local_filter.filter.raw); if(list_is_incomplete(view)) { char full_path[PATH_MAX + 1]; dir_entry_t *entry; get_current_full_path(view, sizeof(full_path), full_path); filter_clear(&view->local_filter.filter); (void)populate_dir_list(view, 1); /* Resolve current file position in updated list. */ entry = entry_from_path(view, view->dir_entry, view->list_rows, full_path); if(entry != NULL) { current_file_pos = entry_to_pos(view, entry); } if(current_file_pos >= view->list_rows) { current_file_pos = view->list_rows - 1; } } else { /* Save unfiltered (by local filter) list for further use. */ replace_dir_entries(view, &view->local_filter.entries, &view->local_filter.entry_count, view->dir_entry, view->list_rows); } view->local_filter.unfiltered = view->dir_entry; view->local_filter.unfiltered_count = view->list_rows; view->local_filter.prefiltered_count = view->filtered; view->dir_entry = NULL; return current_file_pos; }