+extern int cleanup_got_literal;
+extern int remove_source_files;
+extern int append_mode;
+extern int sparse_files;
+extern int keep_partial;
+extern int checksum_seed;
+extern int inplace;
+extern int delay_updates;
+extern mode_t orig_umask;
+extern struct stats stats;
+extern char *tmpdir;
+extern char *partial_dir;
+extern char *basis_dir[];
+extern struct file_list *cur_flist, *first_flist, *dir_flist;
+extern struct filter_list_struct daemon_filter_list;
+
+static struct bitbag *delayed_bits = NULL;
+static int phase = 0, redoing = 0;
+/* We're either updating the basis file or an identical copy: */
+static int updating_basis_or_equiv;
+
+/*
+ * get_tmpname() - create a tmp filename for a given filename
+ *
+ * If a tmpdir is defined, use that as the directory to
+ * put it in. Otherwise, the tmp filename is in the same
+ * directory as the given name. Note that there may be no
+ * directory at all in the given name!
+ *
+ * The tmp filename is basically the given filename with a
+ * dot prepended, and .XXXXXX appended (for mkstemp() to
+ * put its unique gunk in). Take care to not exceed
+ * either the MAXPATHLEN or NAME_MAX, esp. the last, as
+ * the basename basically becomes 8 chars longer. In that
+ * case, the original name is shortened sufficiently to
+ * make it all fit.
+ *
+ * Of course, there's no real reason for the tmp name to
+ * look like the original, except to satisfy us humans.
+ * As long as it's unique, rsync will work.
+ */
+
+int get_tmpname(char *fnametmp, const char *fname)
+{
+ int maxname, added, length = 0;
+ const char *f;