+#if SUPPORT_HARD_LINKS
+ if (idev_len) {
+ file->link_u.idev = (struct idev *)bp;
+ bp += idev_len;
+ }
+#endif
+
+ if (dirname_len) {
+ file->dirname = lastdir = bp;
+ lastdir_len = dirname_len - 1;
+ memcpy(bp, dirname, dirname_len - 1);
+ bp += dirname_len;
+ bp[-1] = '\0';
+ } else if (dirname)
+ file->dirname = dirname;
+
+ file->basename = bp;
+ memcpy(bp, basename, basename_len);
+ bp += basename_len;
+
+ if (preserve_devices && IS_DEVICE(mode))
+ file->u.rdev = rdev;
+
+#if SUPPORT_LINKS
+ if (linkname_len) {
+ file->u.link = bp;
+ read_sbuf(f, bp, linkname_len - 1);
+ if (sanitize_paths)
+ sanitize_path(bp, lastdir);
+ bp += linkname_len;
+ }
+#endif
+
+#if SUPPORT_HARD_LINKS
+ if (idev_len) {
+ if (protocol_version < 26) {
+ dev = read_int(f);
+ file->F_INODE = read_int(f);
+ } else {
+ if (!(flags & XMIT_SAME_DEV))
+ dev = read_longint(f);
+ file->F_INODE = read_longint(f);
+ }
+ file->F_DEV = dev;
+ }
+#endif
+
+ if (always_checksum) {
+ char *sum;
+ if (sum_len) {
+ file->u.sum = sum = bp;
+ /*bp += sum_len;*/
+ } else if (protocol_version < 28) {
+ /* Prior to 28, we get a useless set of nulls. */
+ sum = empty_sum;
+ } else
+ sum = NULL;
+ if (sum) {
+ read_buf(f, sum, protocol_version < 21? 2
+ : MD4_SUM_LENGTH);
+ }
+ }
+
+ if (!preserve_perms) {
+ extern int orig_umask;
+ /* set an appropriate set of permissions based on original
+ * permissions and umask. This emulates what GNU cp does */
+ file->mode &= ~orig_umask;
+ }
+}
+
+
+/**
+ * Create a file_struct for a named file by reading its stat()
+ * information and performing extensive checks against global
+ * options.
+ *
+ * @return the new file, or NULL if there was an error or this file
+ * should be excluded.
+ *
+ * @todo There is a small optimization opportunity here to avoid
+ * stat()ing the file in some circumstances, which has a certain cost.
+ * We are called immediately after doing readdir(), and so we may
+ * already know the d_type of the file. We could for example avoid
+ * statting directories if we're not recursing, but this is not a very
+ * important case. Some systems may not have d_type.
+ **/
+struct file_struct *make_file(char *fname, int exclude_level)
+{
+ static char *lastdir;
+ static int lastdir_len = -1;
+ struct file_struct *file;
+ STRUCT_STAT st;
+ char sum[SUM_LENGTH];
+ char thisname[MAXPATHLEN];
+ char linkname[MAXPATHLEN];
+ int alloc_len, basename_len, dirname_len, linkname_len, sum_len;
+ int file_struct_len, idev_len;
+ char *basename, *dirname, *bp;
+ unsigned short flags = 0;
+
+ if (strlcpy(thisname, fname, sizeof thisname)
+ >= sizeof thisname - flist_dir_len) {
+ rprintf(FINFO, "skipping overly long name: %s\n", fname);