Deleted Added
full compact
dd.c (114433) dd.c (126667)
1/*-
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Keith Muller of the University of California, San Diego and Lance
7 * Visser of Convex Computer Corporation.
8 *

--- 33 unchanged lines hidden (view full) ---

42 The Regents of the University of California. All rights reserved.\n";
43#endif /* not lint */
44
45#ifndef lint
46static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
47#endif /* not lint */
48#endif
49#include <sys/cdefs.h>
1/*-
2 * Copyright (c) 1991, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Keith Muller of the University of California, San Diego and Lance
7 * Visser of Convex Computer Corporation.
8 *

--- 33 unchanged lines hidden (view full) ---

42 The Regents of the University of California. All rights reserved.\n";
43#endif /* not lint */
44
45#ifndef lint
46static char sccsid[] = "@(#)dd.c 8.5 (Berkeley) 4/2/94";
47#endif /* not lint */
48#endif
49#include <sys/cdefs.h>
50__FBSDID("$FreeBSD: head/bin/dd/dd.c 114433 2003-05-01 16:58:57Z obrien $");
50__FBSDID("$FreeBSD: head/bin/dd/dd.c 126667 2004-03-05 19:35:51Z phk $");
51
52#include <sys/param.h>
53#include <sys/stat.h>
54#include <sys/conf.h>
55#include <sys/disklabel.h>
56#include <sys/filio.h>
57#include <sys/time.h>
58

--- 40 unchanged lines hidden (view full) ---

99
100 while (files_cnt--)
101 dd_in();
102
103 dd_close();
104 exit(0);
105}
106
51
52#include <sys/param.h>
53#include <sys/stat.h>
54#include <sys/conf.h>
55#include <sys/disklabel.h>
56#include <sys/filio.h>
57#include <sys/time.h>
58

--- 40 unchanged lines hidden (view full) ---

99
100 while (files_cnt--)
101 dd_in();
102
103 dd_close();
104 exit(0);
105}
106
107static int
108parity(u_char c)
109{
110 int i;
111
112 i = c ^ (c >> 1) ^ (c >> 2) ^ (c >> 3) ^
113 (c >> 4) ^ (c >> 5) ^ (c >> 6) ^ (c >> 7);
114 return (i & 1);
115}
116
107static void
108setup(void)
109{
110 u_int cnt;
111 struct timeval tv;
112
113 if (in.name == NULL) {
114 in.name = "stdin";

--- 56 unchanged lines hidden (view full) ---

171 * Truncate the output file. If it fails on a type of output file
172 * that it should _not_ fail on, error out.
173 */
174 if ((ddflags & (C_OF | C_SEEK | C_NOTRUNC)) == (C_OF | C_SEEK) &&
175 out.flags & ISTRUNC)
176 if (ftruncate(out.fd, out.offset * out.dbsz) == -1)
177 err(1, "truncating %s", out.name);
178
117static void
118setup(void)
119{
120 u_int cnt;
121 struct timeval tv;
122
123 if (in.name == NULL) {
124 in.name = "stdin";

--- 56 unchanged lines hidden (view full) ---

181 * Truncate the output file. If it fails on a type of output file
182 * that it should _not_ fail on, error out.
183 */
184 if ((ddflags & (C_OF | C_SEEK | C_NOTRUNC)) == (C_OF | C_SEEK) &&
185 out.flags & ISTRUNC)
186 if (ftruncate(out.fd, out.offset * out.dbsz) == -1)
187 err(1, "truncating %s", out.name);
188
179 /*
180 * If converting case at the same time as another conversion, build a
181 * table that does both at once. If just converting case, use the
182 * built-in tables.
183 */
184 if (ddflags & (C_LCASE | C_UCASE)) {
185 if (ddflags & (C_ASCII | C_EBCDIC)) {
186 if (ddflags & C_LCASE) {
187 for (cnt = 0; cnt <= 0377; ++cnt)
188 casetab[cnt] = tolower(ctab[cnt]);
189 } else {
190 for (cnt = 0; cnt <= 0377; ++cnt)
191 casetab[cnt] = toupper(ctab[cnt]);
192 }
189 if (ddflags & (C_LCASE | C_UCASE | C_ASCII | C_EBCDIC | C_PARITY)) {
190 if (ctab != NULL) {
191 for (cnt = 0; cnt <= 0377; ++cnt)
192 casetab[cnt] = ctab[cnt];
193 } else {
193 } else {
194 if (ddflags & C_LCASE) {
195 for (cnt = 0; cnt <= 0377; ++cnt)
196 casetab[cnt] = tolower((int)cnt);
197 } else {
198 for (cnt = 0; cnt <= 0377; ++cnt)
199 casetab[cnt] = toupper((int)cnt);
200 }
194 for (cnt = 0; cnt <= 0377; ++cnt)
195 casetab[cnt] = cnt;
201 }
196 }
197 if ((ddflags & C_PARITY) && !(ddflags & C_ASCII)) {
198 /*
199 * If the input is not EBCDIC, and we do parity
200 * processing, strip input parity.
201 */
202 for (cnt = 200; cnt <= 0377; ++cnt)
203 casetab[cnt] = casetab[cnt & 0x7f];
204 }
205 if (ddflags & C_LCASE) {
206 for (cnt = 0; cnt <= 0377; ++cnt)
207 casetab[cnt] = tolower(casetab[cnt]);
208 } else if (ddflags & C_UCASE) {
209 for (cnt = 0; cnt <= 0377; ++cnt)
210 casetab[cnt] = toupper(casetab[cnt]);
211 }
212 if ((ddflags & C_PARITY)) {
213 /*
214 * This should strictly speaking be a no-op, but I
215 * wonder what funny LANG settings could get us.
216 */
217 for (cnt = 0; cnt <= 0377; ++cnt)
218 casetab[cnt] = casetab[cnt] & 0x7f;
219 }
220 if ((ddflags & C_PARSET)) {
221 for (cnt = 0; cnt <= 0377; ++cnt)
222 casetab[cnt] = casetab[cnt] | 0x80;
223 }
224 if ((ddflags & C_PAREVEN)) {
225 for (cnt = 0; cnt <= 0377; ++cnt)
226 if (parity(casetab[cnt]))
227 casetab[cnt] = casetab[cnt] | 0x80;
228 }
229 if ((ddflags & C_PARODD)) {
230 for (cnt = 0; cnt <= 0377; ++cnt)
231 if (!parity(casetab[cnt]))
232 casetab[cnt] = casetab[cnt] | 0x80;
233 }
234
202 ctab = casetab;
203 }
204
205 (void)gettimeofday(&tv, (struct timezone *)NULL);
206 st.start = tv.tv_sec + tv.tv_usec * 1e-6;
207}
208
209static void

--- 251 unchanged lines hidden ---
235 ctab = casetab;
236 }
237
238 (void)gettimeofday(&tv, (struct timezone *)NULL);
239 st.start = tv.tv_sec + tv.tv_usec * 1e-6;
240}
241
242static void

--- 251 unchanged lines hidden ---