4 * $DragonFly: src/bin/cpdup/misc.c,v 1.16 2008/09/15 20:13:16 thomas Exp $
10 logstd(const char *ctl, ...)
20 logerr(const char *ctl, ...)
25 vfprintf(stderr, ctl, va);
30 mprintf(const char *ctl, ...)
38 if (vasprintf(&ptr, ctl, va) < 0)
39 fatal("malloc failed");
46 fextract(FILE *fi, int n, int *pc, int skip)
55 imax = (n < 0) ? 64 : n + 1;
59 fatal("out of memory");
62 if (n == 0 || (n < 0 && (c == ' ' || c == '\n')))
70 fatal("out of memory");
76 if (c == skip && skip != EOF)
84 hc_bswap16(int16_t var)
86 return ((var & 0xff) << 8 | (var >> 8 & 0xff));
90 hc_bswap32(int32_t var)
92 return ((var & 0xff) << 24 | (var & 0xff00) << 8
93 | (var >> 8 & 0xff00) | (var >> 24 & 0xff));
97 hc_bswap64(int64_t var)
99 return (hc_bswap32(var >> 32 & 0xffffffff)
100 | (int64_t) hc_bswap32(var & 0xffffffff) << 32);
109 struct malloc_info *next;
110 struct malloc_info *prev;
116 struct malloc_info DummyInfo = { &DummyInfo, &DummyInfo, NULL, 0, 0 };
117 struct malloc_info *InfoList = &DummyInfo;
120 debug_malloc(size_t bytes, const char *file, int line)
122 struct malloc_info *info = malloc(sizeof(*info) + bytes);
124 info->magic = 0x5513A4C2;
128 info->next = InfoList;
129 info->prev = InfoList->prev;
130 info->next->prev = info;
131 info->prev->next = info;
136 debug_free(void *ptr)
138 struct malloc_info *info = (struct malloc_info *)ptr - 1;
139 struct malloc_info *scan;
142 for (scan = DummyInfo.next; scan != &DummyInfo; scan = scan->next) {
144 assert(info->magic == 0x5513A4C2);
146 info->next->prev = info->prev;
147 info->prev->next = info->next;
152 if (scan == &DummyInfo)
155 if ((++report & 65535) == 0) {
156 printf("--- report\n");
157 for (scan = DummyInfo.next; scan != &DummyInfo; scan = scan->next) {
158 printf("%-15s %d\n", scan->file, scan->line);
166 fatal(const char *ctl, ...)
171 puts("cpdup [<options>] src [dest]");
172 puts(" -C request compressed ssh link if remote operation\n"
173 " -v[vv] verbose level (-vv is typical)\n"
174 " -d print directories being traversed\n"
175 " -u use unbuffered output for -v[vv]\n"
176 " -I display performance summary\n"
177 " -f force update even if files look the same\n"
178 " -F<ssh_opt> Add <ssh_opt> to options passed to ssh\n"
179 " -i0 do NOT confirm when removing something\n"
180 " -j0 do not try to recreate CHR or BLK devices\n"
181 " -l force line-buffered stdout/stderr\n"
182 " -s0 disable safeties - allow files to overwrite directories\n"
183 " -q quiet operation\n"
184 " -o do not remove any files, just overwrite/add\n"
187 " -k maintain/generate FSMID checkfile on target,\n"
188 " and compare source FSMIDs against the checkfiles\n"
189 " -K file -k+specify FSMID checkfile, else .FSMID.CHECK\n"
191 " -m maintain/generate MD5 checkfile on source,\n"
192 " and compare with (optional) destination,\n"
193 " copying if the compare fails\n"
194 " -M file -m+specify MD5 checkfile, else .MD5_CHECKSUMS\n"
195 " copy if md5 check fails\n"
197 " -H path hardlink from path to target instead of copying\n"
198 " source to target, if source matches path.\n"
199 " -V verify file contents even if they appear\n"
201 " -VV same as -V but ignore mtime entirely\n"
202 " -x use .cpignore as exclusion file\n"
203 " -X file specify exclusion file\n"
204 " Version 1.16.3 by Matt Dillon and Dima Ruban\n"
209 vfprintf(stderr, ctl, va);