if (!fp) {
if (errno != ENOENT)
- warning(_("unable to access '%s': %s"), path, strerror(errno));
+ warn_on_inaccessible(path);
return NULL;
}
res = xcalloc(1, sizeof(*res));
fd = open(fname, O_RDONLY);
if (fd < 0 || fstat(fd, &st) < 0) {
if (errno != ENOENT)
- warning(_("unable to access '%s': %s"), fname, strerror(errno));
+ warn_on_inaccessible(fname);
if (0 <= fd)
close(fd);
if (!check_index ||
/* Call access(2), but warn for any error besides ENOENT. */
int access_or_warn(const char *path, int mode);
+/* Warn on an inaccessible file that ought to be accessible */
+void warn_on_inaccessible(const char *path);
+
/* Get the passwd entry for the UID of the current process. */
struct passwd *xgetpwuid_self(void);
return S_ISGITLINK(mode) ? rmdir_or_warn(file) : unlink_or_warn(file);
}
+void warn_on_inaccessible(const char *path)
+{
+ warning(_("unable to access '%s': %s"), path, strerror(errno));
+}
+
int access_or_warn(const char *path, int mode)
{
int ret = access(path, mode);
if (ret && errno != ENOENT)
- warning(_("unable to access '%s': %s"), path, strerror(errno));
+ warn_on_inaccessible(path);
return ret;
}