+static char topsrcname[MAXPATHLEN];
+
+static struct exclude_struct **local_exclude_list;
+
+static struct file_struct null_file;
+
+static void clean_flist(struct file_list *flist, int strip_root);
+
+static struct string_area *string_area_new(int size)
+{
+ struct string_area *a;
+
+ if (size <= 0) size = ARENA_SIZE;
+ a = malloc(sizeof(*a));
+ if (!a) out_of_memory("string_area_new");
+ a->current = a->base = malloc(size);
+ if (!a->current) out_of_memory("string_area_new buffer");
+ a->end = a->base + size;
+ a->next = NULL;
+
+ return a;
+}
+
+static void string_area_free(struct string_area *a)
+{
+ struct string_area *next;
+
+ for ( ; a ; a = next) {
+ next = a->next;
+ free(a->base);
+ }
+}
+
+static char *string_area_malloc(struct string_area **ap, int size)
+{
+ char *p;
+ struct string_area *a;
+
+ /* does the request fit into the current space? */
+ a = *ap;
+ if (a->current + size >= a->end) {
+ /* no; get space, move new string_area to front of the list */
+ a = string_area_new(size > ARENA_SIZE ? size : ARENA_SIZE);
+ a->next = *ap;
+ *ap = a;
+ }
+
+ /* have space; do the "allocation." */
+ p = a->current;
+ a->current += size;
+ return p;
+}
+
+static char *string_area_strdup(struct string_area **ap, const char *src)
+{
+ char* dest = string_area_malloc(ap, strlen(src) + 1);
+ return strcpy(dest, src);
+}
+
+static void list_file_entry(struct file_struct *f)
+{
+ char perms[11] = "----------";
+ char *perm_map = "rwxrwxrwx";
+ int i;
+
+ if (!f->basename)
+ /* this can happen if duplicate names were removed */
+ return;
+
+ for (i=0;i<9;i++) {
+ if (f->mode & (1<<i)) perms[9-i] = perm_map[8-i];
+ }
+ if (S_ISLNK(f->mode)) perms[0] = 'l';
+ if (S_ISDIR(f->mode)) perms[0] = 'd';
+ if (S_ISBLK(f->mode)) perms[0] = 'b';
+ if (S_ISCHR(f->mode)) perms[0] = 'c';
+ if (S_ISSOCK(f->mode)) perms[0] = 's';
+ if (S_ISFIFO(f->mode)) perms[0] = 'p';
+
+ if (preserve_links && S_ISLNK(f->mode)) {
+ rprintf(FINFO,"%s %11.0f %s %s -> %s\n",
+ perms,
+ (double)f->length, timestring(f->modtime),
+ f_name(f), f->link);
+ } else {
+ rprintf(FINFO,"%s %11.0f %s %s\n",
+ perms,
+ (double)f->length, timestring(f->modtime), f_name(f));
+ }
+}
+
+
+int readlink_stat(const char *Path, STRUCT_STAT *Buffer, char *Linkbuf)
+{
+#if SUPPORT_LINKS
+ if (copy_links) {
+ return do_stat(Path, Buffer);
+ }
+ if (do_lstat(Path, Buffer) == -1) {
+ return -1;
+ }
+ if (S_ISLNK(Buffer->st_mode)) {
+ int l;
+ if ((l = readlink(Path,Linkbuf,MAXPATHLEN-1)) == -1) {
+ return -1;
+ }
+ Linkbuf[l] = 0;
+ if (copy_unsafe_links && (topsrcname[0] != '\0') &&
+ unsafe_symlink(Linkbuf, topsrcname)) {
+ return do_stat(Path, Buffer);
+ }
+ }
+ return 0;
+#else
+ return do_stat(Path, Buffer);
+#endif
+}