From fde0f40e873c9539e6554da8288b4912b8e0666c Mon Sep 17 00:00:00 2001 From: wm4 Date: Sat, 7 Sep 2013 20:24:02 +0200 Subject: find_subfiles: use stat() instead of opening the file to check existence Use mp_path_exists() to check for existence of a file (which in turn uses stat()), instead of opening and closing it. The difference is that if we don't have sufficient permissions to read the subtitle files, we will loudly complain. Personally, I prefer this behavior. --- sub/find_subfiles.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/sub/find_subfiles.c b/sub/find_subfiles.c index 46ee3df0a9..2af7dafbd7 100644 --- a/sub/find_subfiles.c +++ b/sub/find_subfiles.c @@ -87,7 +87,6 @@ static void append_dir_subtitles(struct MPOpts *opts, { char *sub_exts[] = {"utf", "utf8", "utf-8", "idx", "sub", "srt", "smi", "rt", "txt", "ssa", "aqt", "jss", "js", "ass", NULL}; void *tmpmem = talloc_new(NULL); - FILE *f; assert(strlen(fname) < 1e6); if (mp_is_url(bstr0(fname))) @@ -174,11 +173,10 @@ static void append_dir_subtitles(struct MPOpts *opts, prio++; #endif char *subpath = mp_path_join(*slist, path, dename); - if ((f = fopen(subpath, "rt"))) { + if (mp_path_exists(subpath)) { MP_GROW_ARRAY(*slist, *nsub); struct subfn *sub = *slist + (*nsub)++; - fclose(f); sub->priority = prio; sub->fname = subpath; } else -- cgit v1.2.3