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 fprintf(stderr, "out of memory\n");
64 if (n == 0 || (n < 0 && (c == ' ' || c == '\n')))
72 fprintf(stderr, "out of memory\n");
80 if (c == skip && skip != EOF)
93 struct malloc_info *next;
94 struct malloc_info *prev;
100 struct malloc_info DummyInfo = { &DummyInfo, &DummyInfo, NULL, 0, 0 };
101 struct malloc_info *InfoList = &DummyInfo;
104 debug_malloc(size_t bytes, const char *file, int line)
106 struct malloc_info *info = malloc(sizeof(*info) + bytes);
108 info->magic = 0x5513A4C2;
112 info->next = InfoList;
113 info->prev = InfoList->prev;
114 info->next->prev = info;
115 info->prev->next = info;
120 debug_free(void *ptr)
122 struct malloc_info *info = (struct malloc_info *)ptr - 1;
123 struct malloc_info *scan;
126 for (scan = DummyInfo.next; scan != &DummyInfo; scan = scan->next) {
128 assert(info->magic == 0x5513A4C2);
130 info->next->prev = info->prev;
131 info->prev->next = info->next;
136 if (scan == &DummyInfo)
139 if ((++report & 65535) == 0) {
140 printf("--- report\n");
141 for (scan = DummyInfo.next; scan != &DummyInfo; scan = scan->next) {
142 printf("%-15s %d\n", scan->file, scan->line);
150 fatal(const char *ctl, ...)
155 puts("cpdup [<options>] src [dest]");
156 puts(" -C request compressed ssh link if remote operation\n"
157 " -v[vv] verbose level (-vv is typical)\n"
158 " -u use unbuffered output for -v[vv]\n"
159 " -I display performance summary\n"
160 " -f force update even if files look the same\n"
161 " -i0 do NOT confirm when removing something\n"
162 " -l force line-buffered stdout/stderr\n"
163 " -pN N parallel transactions for for remote\n"
164 " source or destination\n"
165 " -s0 disable safeties - allow files to overwrite directories\n"
166 " -q quiet operation\n"
167 " -o do not remove any files, just overwrite/add\n"
171 " -m maintain/generate MD5 checkfile on source,\n"
172 " and compare with (optional) destination,\n"
173 " copying if the compare fails\n"
174 " -M file -m+specify MD5 checkfile, else .MD5_CHECKSUMS\n"
175 " copy if md5 check fails\n"
176 " -H path hardlink from path to target instead of copying\n"
177 " source to target, if source matches path.\n"
178 " -V verify file contents even if they appear\n"
181 " -x use .cpignore as exclusion file\n"
182 " -X file specify exclusion file\n"
183 " Version 1.14 by Matt Dillon and Dima Ruban\n"