Merge from vendor branch OPENSSH:
[dragonfly.git] / bin / cpdup / misc.c
1 /*
2  * MISC.C
3  *
4  * $DragonFly: src/bin/cpdup/misc.c,v 1.4 2004/06/09 07:40:15 cpressey 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              "    -u          use unbuffered output for -v[vv]\n"
52              "    -I          display performance summary\n"
53              "    -f          force update even if files look the same\n"
54              "    -i0         do NOT confirm when removing something\n"
55              "    -s0         disable safeties - allow files to overwrite directories\n"
56              "    -q          quiet operation\n"
57              "    -o          do not remove any files, just overwrite/add\n"
58         );
59         puts("    -m          maintain/generate MD5 checkfile on source,\n"
60              "                and compare with (optional) destination,\n"
61              "                copying if the compare fails\n"
62              "    -M file     -m+specify MD5 checkfile, else .MD5_CHECKSUMS\n"
63              "                copy if md5 check fails\n"
64              "    -x          use .cpignore as exclusion file\n"
65              "    -X file     specify exclusion file\n"
66              " Version 1.06 by Matt Dillon and Dima Ruban\n"
67         );
68         exit(0);
69     } else {
70         va_start(va, ctl);
71         vprintf(ctl, va);
72         va_end(va);
73         puts("");
74         exit(1);
75     }
76 }
77