8 logstd(const char *ctl, ...)
18 logerr(const char *ctl, ...)
23 vfprintf(stderr, ctl, va);
28 mprintf(const char *ctl, ...)
36 if (vasprintf(&ptr, ctl, va) < 0)
37 fatal("malloc failed");
44 fextract(FILE *fi, int n, int *pc, int skip)
53 imax = (n < 0) ? 64 : n + 1;
57 fatal("out of memory");
60 if (n == 0 || (n < 0 && (c == ' ' || c == '\n')))
68 fatal("out of memory");
74 if (c == skip && skip != EOF)
82 hc_bswap16(int16_t var)
84 return ((var & 0xff) << 8 | (var >> 8 & 0xff));
88 hc_bswap32(int32_t var)
90 return ((var & 0xff) << 24 | (var & 0xff00) << 8
91 | (var >> 8 & 0xff00) | (var >> 24 & 0xff));
95 hc_bswap64(int64_t var)
97 return (hc_bswap32(var >> 32 & 0xffffffff)
98 | (int64_t) hc_bswap32(var & 0xffffffff) << 32);
107 struct malloc_info *next;
108 struct malloc_info *prev;
114 struct malloc_info DummyInfo = { &DummyInfo, &DummyInfo, NULL, 0, 0 };
115 struct malloc_info *InfoList = &DummyInfo;
118 debug_malloc(size_t bytes, const char *file, int line)
120 struct malloc_info *info = malloc(sizeof(*info) + bytes);
122 info->magic = 0x5513A4C2;
126 info->next = InfoList;
127 info->prev = InfoList->prev;
128 info->next->prev = info;
129 info->prev->next = info;
134 debug_free(void *ptr)
136 struct malloc_info *info = (struct malloc_info *)ptr - 1;
137 struct malloc_info *scan;
140 for (scan = DummyInfo.next; scan != &DummyInfo; scan = scan->next) {
142 assert(info->magic == 0x5513A4C2);
144 info->next->prev = info->prev;
145 info->prev->next = info->next;
150 if (scan == &DummyInfo)
153 if ((++report & 65535) == 0) {
154 printf("--- report\n");
155 for (scan = DummyInfo.next; scan != &DummyInfo; scan = scan->next) {
156 printf("%-15s %d\n", scan->file, scan->line);
164 fatal(const char *ctl, ...)
169 puts("cpdup [<options>] src [dest]");
170 puts(" -C request compressed ssh link if remote operation\n"
171 " -v[vv] verbose level (-vv is typical)\n"
172 " -d print directories being traversed\n"
173 " -u use unbuffered output for -v[vv]\n"
174 " -I display performance summary\n"
175 " -f force update even if files look the same\n"
176 " -F<ssh_opt> Add <ssh_opt> to options passed to ssh\n"
177 " -i0 do NOT confirm when removing something\n"
178 " -j0 do not try to recreate CHR or BLK devices\n"
179 " -l force line-buffered stdout/stderr\n"
180 " -s0 disable safeties - allow files to overwrite directories\n"
181 " -q quiet operation\n"
182 " -o do not remove any files, just overwrite/add\n"
185 " -k maintain/generate FSMID checkfile on target,\n"
186 " and compare source FSMIDs against the checkfiles\n"
187 " -K file -k+specify FSMID checkfile, else .FSMID.CHECK\n"
189 " -m maintain/generate MD5 checkfile on source,\n"
190 " and compare with (optional) destination,\n"
191 " copying if the compare fails\n"
192 " -M file -m+specify MD5 checkfile, else .MD5_CHECKSUMS\n"
193 " copy if md5 check fails\n"
195 " -H path hardlink from path to target instead of copying\n"
196 " -R read-only slave mode for ssh remotes\n"
197 " source to target, if source matches path.\n"
198 " -V verify file contents even if they appear\n"
200 " -VV same as -V but ignore mtime entirely\n"
201 " -x use .cpignore as exclusion file\n"
202 " -X file specify exclusion file\n"
203 " Version 1.19 by Matt Dillon, Dima Ruban, & Oliver Fromme\n"
208 vfprintf(stderr, ctl, va);