Changeset View
Changeset View
Standalone View
Standalone View
head/bin/dd/dd.c
Show First 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | |||||
char fill_char; /* Character to fill with if defined */ | char fill_char; /* Character to fill with if defined */ | ||||
size_t speed = 0; /* maximum speed, in bytes per second */ | size_t speed = 0; /* maximum speed, in bytes per second */ | ||||
volatile sig_atomic_t need_summary; | volatile sig_atomic_t need_summary; | ||||
volatile sig_atomic_t need_progress; | volatile sig_atomic_t need_progress; | ||||
int | int | ||||
main(int argc __unused, char *argv[]) | main(int argc __unused, char *argv[]) | ||||
{ | { | ||||
struct itimerval itv = { { 1, 0 }, { 1, 0 } }; /* SIGALARM every second, if needed */ | |||||
(void)setlocale(LC_CTYPE, ""); | (void)setlocale(LC_CTYPE, ""); | ||||
jcl(argv); | jcl(argv); | ||||
setup(); | setup(); | ||||
caph_cache_catpages(); | caph_cache_catpages(); | ||||
if (caph_enter() < 0) | if (caph_enter() < 0) | ||||
err(1, "unable to enter capability mode"); | err(1, "unable to enter capability mode"); | ||||
(void)signal(SIGINFO, siginfo_handler); | (void)signal(SIGINFO, siginfo_handler); | ||||
(void)signal(SIGALRM, sigalrm_handler); | if (ddflags & C_PROGRESS) { | ||||
(void)signal(SIGALRM, sigalarm_handler); | |||||
setitimer(ITIMER_REAL, &itv, NULL); | |||||
} | |||||
(void)signal(SIGINT, terminate); | (void)signal(SIGINT, terminate); | ||||
atexit(summary); | atexit(summary); | ||||
while (files_cnt--) | while (files_cnt--) | ||||
dd_in(); | dd_in(); | ||||
dd_close(); | dd_close(); | ||||
▲ Show 20 Lines • Show All 163 Lines • ▼ Show 20 Lines | if ((ddflags & C_PARODD)) { | ||||
for (cnt = 0; cnt <= 0377; ++cnt) | for (cnt = 0; cnt <= 0377; ++cnt) | ||||
if (!parity(casetab[cnt])) | if (!parity(casetab[cnt])) | ||||
casetab[cnt] = casetab[cnt] | 0x80; | casetab[cnt] = casetab[cnt] | 0x80; | ||||
} | } | ||||
ctab = casetab; | ctab = casetab; | ||||
} | } | ||||
if ((ddflags & C_PROGRESS)) { | |||||
struct itimerval timer = { | |||||
.it_interval = { .tv_sec = 1, .tv_usec = 0 }, | |||||
.it_value = { .tv_sec = 1, .tv_usec = 0 }, | |||||
}; | |||||
setitimer(ITIMER_REAL, &timer, NULL); | |||||
} | |||||
if (clock_gettime(CLOCK_MONOTONIC, &st.start)) | if (clock_gettime(CLOCK_MONOTONIC, &st.start)) | ||||
err(1, "clock_gettime"); | err(1, "clock_gettime"); | ||||
} | } | ||||
static void | static void | ||||
getfdtype(IO *io) | getfdtype(IO *io) | ||||
{ | { | ||||
struct stat sb; | struct stat sb; | ||||
▲ Show 20 Lines • Show All 161 Lines • ▼ Show 20 Lines | if (ddflags & C_SWAB) { | ||||
++st.swab; | ++st.swab; | ||||
--n; | --n; | ||||
} | } | ||||
swapbytes(in.dbp, (size_t)n); | swapbytes(in.dbp, (size_t)n); | ||||
} | } | ||||
in.dbp += in.dbrcnt; | in.dbp += in.dbrcnt; | ||||
(*cfunc)(); | (*cfunc)(); | ||||
if (need_summary) { | if (need_summary) | ||||
summary(); | summary(); | ||||
} | if (need_progress) | ||||
if (need_progress) { | |||||
progress(); | progress(); | ||||
} | |||||
} | } | ||||
} | } | ||||
/* | /* | ||||
* Clean up any remaining I/O and flush output. If necessary, the output file | * Clean up any remaining I/O and flush output. If necessary, the output file | ||||
* is truncated. | * is truncated. | ||||
*/ | */ | ||||
static void | static void | ||||
▲ Show 20 Lines • Show All 138 Lines • Show Last 20 Lines |