From 74e3e46f469dc6d8764eebff96f979fced99da66 Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Tue, 24 May 2016 18:08:44 +0530 Subject: [PATCH] browser: Move opendir() & closedir() to do_browser() Move opendir() & closedir() to do_browser() from do_browse_from() & browser_init(), respectively, to make these operations clear while reading the program. This makes dir parameter redundant for do_browser() & do_browse_from(), so it is removed. Signed-off-by: Rishabh Dave --- src/browser.c | 24 +++++++++++------------- src/proto.h | 2 +- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/src/browser.c b/src/browser.c index 6e16aed..4f45290 100644 --- a/src/browser.c +++ b/src/browser.c @@ -44,7 +44,7 @@ static size_t selected = 0; /* Our main file browser function. path is the tilde-expanded path we * start browsing from. */ -char *do_browser(char *path, DIR *dir) +char *do_browser(char *path) { char *retval = NULL; int kbinput; @@ -55,6 +55,15 @@ char *do_browser(char *path, DIR *dir) /* The number of the selected file before the current selected file. */ functionptrtype func; /* The function of the key the user typed in. */ + DIR *dir = NULL; + + dir = opendir(path); + /* If we can't open the path, get out. */ + if (dir == NULL) { + free(path); + beep(); + return NULL; + } /* Don't show a cursor in the file list. */ curs_set(0); @@ -364,7 +373,6 @@ char *do_browse_from(const char *inpath) struct stat st; char *path; /* This holds the tilde-expanded version of inpath. */ - DIR *dir = NULL; assert(inpath != NULL); @@ -403,17 +411,7 @@ char *do_browse_from(const char *inpath) path = mallocstrcpy(path, operating_dir); #endif - if (path != NULL) - dir = opendir(path); - - /* If we can't open the path, get out. */ - if (dir == NULL) { - free(path); - beep(); - return NULL; - } - - return do_browser(path, dir); + return do_browser(path); } /* Set filelist to the list of files contained in the directory path, diff --git a/src/proto.h b/src/proto.h index 0024988..61bca28 100644 --- a/src/proto.h +++ b/src/proto.h @@ -150,7 +150,7 @@ typedef void (*functionptrtype)(void); /* All functions in browser.c. */ #ifndef DISABLE_BROWSER -char *do_browser(char *path, DIR *dir); +char *do_browser(char *path); char *do_browse_from(const char *inpath); void browser_init(const char *path, DIR *dir); functionptrtype parse_browser_input(int *kbinput); -- 2.8.3