+/* Use fchmod if possible, chmod otherwise. */
+static int
+fdchmod (char const *file, int fd, mode_t mode)
+{
+#if HAVE_FCHMOD
+ if (0 <= fd)
+ return fchmod (fd, mode);
+#endif
+ return chmod (file, mode);
+}
+
+/* Use fchown if possible, chown otherwise. */
+static int
+fdchown (char const *file, int fd, uid_t uid, gid_t gid)
+{
+#if HAVE_FCHOWN
+ if (0 <= fd)
+ return fchown (fd, uid, gid);
+#endif
+ return chown (file, uid, gid);
+}
+
+/* Use fstat if possible, stat otherwise. */
+static int
+fdstat (char const *file, int fd, struct stat *st)
+{
+ if (0 <= fd)
+ return fstat (fd, st);
+ return stat (file, st);
+}
+