+{
+ int code;
+ if (dry_run) return 0;
+ RETURN_ERROR_IF_RO_OR_LO;
+#ifdef HAVE_LCHMOD
+ code = lchmod(path, mode & CHMOD_BITS);
+#else
+ if (S_ISLNK(mode)) {
+# if defined HAVE_SETATTRLIST
+ struct attrlist attrList;
+ uint32_t m = mode & CHMOD_BITS; /* manpage is wrong: not mode_t! */
+
+ memset(&attrList, 0, sizeof attrList);
+ attrList.bitmapcount = ATTR_BIT_MAP_COUNT;
+ attrList.commonattr = ATTR_CMN_ACCESSMASK;
+ code = setattrlist(path, &attrList, &m, sizeof m, FSOPT_NOFOLLOW);
+# else
+ code = 1;
+# endif
+ } else
+ code = chmod(path, mode & CHMOD_BITS); /* DISCOURAGED FUNCTION */
+#endif /* !HAVE_LCHMOD */
+ if (code != 0 && (preserve_perms || preserve_executability))
+ return code;
+ return 0;
+}
+#endif
+
+int do_rename(const char *fname1, const char *fname2)
+{
+ if (dry_run) return 0;
+ RETURN_ERROR_IF_RO_OR_LO;
+ return rename(fname1, fname2);
+}
+
+void trim_trailing_slashes(char *name)
+{
+ int l;
+ /* Some BSD systems cannot make a directory if the name
+ * contains a trailing slash.
+ * <http://www.opensource.apple.com/bugs/X/BSD%20Kernel/2734739.html> */
+
+ /* Don't change empty string; and also we can't improve on
+ * "/" */
+
+ l = strlen(name);
+ while (l > 1) {
+ if (name[--l] != '/')
+ break;
+ name[l] = '\0';
+ }
+}
+
+int do_mkdir(char *fname, mode_t mode)