xref: /dragonfly/bin/cpdup/misc.c (revision 4caa7869)
1 /*
2  * MISC.C
3  *
4  * $DragonFly: src/bin/cpdup/misc.c,v 1.2 2003/12/01 06:07:16 dillon Exp $
5  */
6 
7 #include "cpdup.h"
8 
9 void
10 logstd(const char *ctl, ...)
11 {
12     va_list va;
13 
14     va_start(va, ctl);
15     vprintf(ctl, va);
16     va_end(va);
17 }
18 
19 void
20 logerr(const char *ctl, ...)
21 {
22     va_list va;
23 
24     va_start(va, ctl);
25     vfprintf(stderr, ctl, va);
26     va_end(va);
27 }
28 
29 char *
30 mprintf(const char *ctl, ...)
31 {
32     char *ptr = NULL;
33     va_list va;
34 
35     va_start(va, ctl);
36     if (vasprintf(&ptr, ctl, va) < 0)
37 	fatal("malloc failed");
38     va_end(va);
39     assert(ptr != NULL);
40     return(ptr);
41 }
42 
43 void
44 fatal(const char *ctl, ...)
45 {
46     va_list va;
47 
48     if (ctl == NULL) {
49 	puts("cpdup [<options>] src [dest]");
50 	puts("    -v[vv]      verbose level (-vv is typical)\n"
51 	     "    -I          display performance summary\n"
52 	     "    -f          force update even if files look the same\n"
53 	     "    -i0         do NOT confirm when removing something\n"
54 	     "    -s0         disable safeties - allow files to overwrite directories\n"
55 	     "    -q          quiet operation\n"
56 	     "    -o          do not remove any files, just overwrite/add\n"
57 	     "    -m          maintain/generate MD5 checkfile on source,\n"
58 	     "                and compare with (optional) destination,\n"
59 	     "                copying if the compare fails\n"
60 	     "    -M file     -m+specify MD5 checkfile, else .MD5_CHECKSUMS\n"
61 	     "                copy if md5 check fails\n"
62 	     "    -x          use .cpignore as exclusion file\n"
63 	     "    -X file     specify exclusion file\n"
64 	     " Version 1.06 by Matt Dillon and Dima Ruban\n"
65 	);
66 	exit(0);
67     } else {
68 	va_start(va, ctl);
69 	vprintf(ctl, va);
70 	va_end(va);
71 	puts("");
72 	exit(1);
73     }
74 }
75 
76