int fd;
struct stat st;
- if (stat (filename, &st) == -1 || !S_ISREG (st.st_mode)) {
- if (must_exist) {
+ if (stat (filename, &st) == -1) {
+ if (must_exist || errno == EPERM) {
ucl_create_err (err, "cannot stat file %s: %s",
filename, strerror (errno));
}
return false;
}
+ if (!S_ISREG (st.st_mode)) {
+ if (must_exist) {
+ ucl_create_err (err, "file %s is not a regular file", filename);
+ }
+
+ return false;
+ }
if (st.st_size == 0) {
/* Do not map empty files */
*buf = NULL;
if (params->soft_fail) {
return false;
}
- if (!params->must_exist) {
+ if (!params->must_exist && errno != EPERM) {
return true;
}
+
ucl_create_err (&parser->err, "cannot open file %s: %s",
filebuf,
strerror (errno));
return false;
}
- return (!params->must_exist || false);
+ if (params->must_exist || parser->err != NULL) {
+ /* The case of fatal errors */
+ return false;
+ }
+
+ return true;
}
if (params->check_signature) {