=================================================================== RCS file: /cvs/mandoc/main.c,v retrieving revision 1.325 retrieving revision 1.326 diff -u -p -r1.325 -r1.326 --- mandoc/main.c 2019/05/03 16:14:42 1.325 +++ mandoc/main.c 2019/05/03 17:31:15 1.326 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.325 2019/05/03 16:14:42 schwarze Exp $ */ +/* $Id: main.c,v 1.326 2019/05/03 17:31:15 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons * Copyright (c) 2010-2012, 2014-2019 Ingo Schwarze @@ -21,6 +21,7 @@ #include #include #include /* MACHINE */ +#include #include #include @@ -713,6 +714,7 @@ fs_lookup(const struct manpaths *paths, size_t ipath, const char *sec, const char *arch, const char *name, struct manpage **res, size_t *ressz) { + struct stat sb; glob_t globinfo; struct manpage *page; char *file; @@ -722,13 +724,13 @@ fs_lookup(const struct manpaths *paths, size_t ipath, form = FORM_SRC; mandoc_asprintf(&file, "%s/man%s/%s.%s", paths->paths[ipath], sec, name, sec); - if (access(file, R_OK) != -1) + if (stat(file, &sb) != -1) goto found; free(file); mandoc_asprintf(&file, "%s/cat%s/%s.0", paths->paths[ipath], sec, name); - if (access(file, R_OK) != -1) { + if (stat(file, &sb) != -1) { form = FORM_CAT; goto found; } @@ -737,7 +739,7 @@ fs_lookup(const struct manpaths *paths, size_t ipath, if (arch != NULL) { mandoc_asprintf(&file, "%s/man%s/%s/%s.%s", paths->paths[ipath], sec, arch, name, sec); - if (access(file, R_OK) != -1) + if (stat(file, &sb) != -1) goto found; free(file); } @@ -751,13 +753,16 @@ fs_lookup(const struct manpaths *paths, size_t ipath, if (globres == 0) file = mandoc_strdup(*globinfo.gl_pathv); globfree(&globinfo); - if (globres == 0) - goto found; + if (globres == 0) { + if (stat(file, &sb) != -1) + goto found; + free(file); + } if (res != NULL || ipath + 1 != paths->sz) return 0; mandoc_asprintf(&file, "%s.%s", name, sec); - globres = access(file, R_OK); + globres = stat(file, &sb); free(file); return globres != -1;