Bump the version number reported by cpdup from 1.06 to 1.07
[dragonfly.git] / bin / cpdup / misc.c
CommitLineData
3a42736d
MD
1/*
2 * MISC.C
3 *
e1a494b3 4 * $DragonFly: src/bin/cpdup/misc.c,v 1.8 2006/09/16 18:18:05 dillon Exp $
3a42736d
MD
5 */
6
7#include "cpdup.h"
8
9void
10logstd(const char *ctl, ...)
11{
12 va_list va;
13
14 va_start(va, ctl);
15 vprintf(ctl, va);
16 va_end(va);
17}
18
19void
20logerr(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
29char *
30mprintf(const char *ctl, ...)
31{
58860d7d 32 char *ptr;
3a42736d
MD
33 va_list va;
34
58860d7d
MD
35 ptr = NULL;
36
3a42736d
MD
37 va_start(va, ctl);
38 if (vasprintf(&ptr, ctl, va) < 0)
39 fatal("malloc failed");
40 va_end(va);
41 assert(ptr != NULL);
42 return(ptr);
43}
44
577109ea
MD
45char *
46fextract(FILE *fi, int n, int *pc, int skip)
47{
48 int i;
49 int c;
50 int imax;
51 char *s;
52
53 i = 0;
54 c = *pc;
55 imax = (n < 0) ? 64 : n + 1;
56
57 s = malloc(imax);
58 if (s == NULL) {
59 fprintf(stderr, "out of memory\n");
60 exit(EXIT_FAILURE);
61 }
62
63 while (c != EOF) {
64 if (n == 0 || (n < 0 && (c == ' ' || c == '\n')))
65 break;
66
67 s[i++] = c;
68 if (i == imax) {
69 imax += 64;
70 s = realloc(s, imax);
71 if (s == NULL) {
72 fprintf(stderr, "out of memory\n");
73 exit(EXIT_FAILURE);
74 }
75 }
76 if (n > 0)
77 --n;
78 c = getc(fi);
79 }
80 if (c == skip && skip != EOF)
81 c = getc(fi);
82 *pc = c;
83 s[i] = 0;
84 return(s);
85}
86
3a42736d
MD
87void
88fatal(const char *ctl, ...)
89{
90 va_list va;
91
92 if (ctl == NULL) {
93 puts("cpdup [<options>] src [dest]");
94 puts(" -v[vv] verbose level (-vv is typical)\n"
4d2076d3 95 " -u use unbuffered output for -v[vv]\n"
3a42736d
MD
96 " -I display performance summary\n"
97 " -f force update even if files look the same\n"
98 " -i0 do NOT confirm when removing something\n"
99 " -s0 disable safeties - allow files to overwrite directories\n"
100 " -q quiet operation\n"
101 " -o do not remove any files, just overwrite/add\n"
1c755102 102 );
4d858d58
MD
103 puts(
104#ifndef NOMD5
105 " -m maintain/generate MD5 checkfile on source,\n"
3a42736d
MD
106 " and compare with (optional) destination,\n"
107 " copying if the compare fails\n"
108 " -M file -m+specify MD5 checkfile, else .MD5_CHECKSUMS\n"
109 " copy if md5 check fails\n"
4d858d58 110#endif
3a42736d
MD
111 " -x use .cpignore as exclusion file\n"
112 " -X file specify exclusion file\n"
e1a494b3 113 " Version 1.07 by Matt Dillon and Dima Ruban\n"
3a42736d
MD
114 );
115 exit(0);
116 } else {
117 va_start(va, ctl);
118 vprintf(ctl, va);
119 va_end(va);
120 puts("");
121 exit(1);
122 }
123}