Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 1 | /* vi: set sw=4 ts=4: */ |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 2 | /* |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 3 | * Mini dd implementation for busybox |
| 4 | * |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 5 | * |
Matt Kraai | 3eeab3b | 2001-12-07 16:27:37 +0000 | [diff] [blame] | 6 | * Copyright (C) 2000,2001 Matt Kraai |
Eric Andersen | c499601 | 1999-10-20 22:08:37 +0000 | [diff] [blame] | 7 | * |
Bernhard Reutner-Fischer | c2cb0f3 | 2006-04-13 12:45:04 +0000 | [diff] [blame] | 8 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
Eric Andersen | cc8ed39 | 1999-10-05 16:24:54 +0000 | [diff] [blame] | 9 | */ |
| 10 | |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 11 | #include "busybox.h" |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 12 | #include <signal.h> /* For FEATURE_DD_SIGNAL_HANDLING */ |
Eric Andersen | cbe31da | 2001-02-20 06:14:08 +0000 | [diff] [blame] | 13 | |
Matt Kraai | a164c64 | 2001-02-05 17:50:03 +0000 | [diff] [blame] | 14 | static const struct suffix_mult dd_suffixes[] = { |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 15 | { "c", 1 }, |
| 16 | { "w", 2 }, |
| 17 | { "b", 512 }, |
| 18 | { "kD", 1000 }, |
| 19 | { "k", 1024 }, |
Denis Vlasenko | 5625415 | 2006-10-07 16:24:46 +0000 | [diff] [blame] | 20 | { "K", 1024 }, // compat with coreutils dd |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 21 | { "MD", 1000000 }, |
| 22 | { "M", 1048576 }, |
| 23 | { "GD", 1000000000 }, |
| 24 | { "G", 1073741824 }, |
| 25 | { NULL, 0 } |
| 26 | }; |
| 27 | |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 28 | static off_t out_full, out_part, in_full, in_part; |
Rob Landley | c559817 | 2006-05-02 22:44:04 +0000 | [diff] [blame] | 29 | |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 30 | static void dd_output_status(int ATTRIBUTE_UNUSED cur_signal) |
Rob Landley | c559817 | 2006-05-02 22:44:04 +0000 | [diff] [blame] | 31 | { |
Denis Vlasenko | cf30cc8 | 2006-11-24 14:53:18 +0000 | [diff] [blame] | 32 | fprintf(stderr, "%"OFF_FMT"d+%"OFF_FMT"d records in\n" |
| 33 | "%"OFF_FMT"d+%"OFF_FMT"d records out\n", |
Denis Vlasenko | 5625415 | 2006-10-07 16:24:46 +0000 | [diff] [blame] | 34 | in_full, in_part, |
| 35 | out_full, out_part); |
Rob Landley | c559817 | 2006-05-02 22:44:04 +0000 | [diff] [blame] | 36 | } |
| 37 | |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 38 | static ssize_t full_write_or_warn(int fd, const void *buf, size_t len, |
| 39 | const char* filename) |
| 40 | { |
| 41 | ssize_t n = full_write(fd, buf, len); |
| 42 | if (n < 0) |
| 43 | bb_perror_msg("writing '%s'", filename); |
| 44 | return n; |
| 45 | } |
| 46 | |
Denis Vlasenko | 5dd27b1 | 2006-11-25 14:46:21 +0000 | [diff] [blame] | 47 | #if ENABLE_LFS |
| 48 | #define XATOU_SFX xatoull_sfx |
| 49 | #else |
| 50 | #define XATOU_SFX xatoul_sfx |
| 51 | #endif |
| 52 | |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 53 | int dd_main(int argc, char **argv) |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 54 | { |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 55 | enum { |
| 56 | sync_flag = 1 << 0, |
| 57 | noerror = 1 << 1, |
| 58 | trunc_flag = 1 << 2, |
| 59 | twobufs_flag = 1 << 3, |
| 60 | }; |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 61 | int flags = trunc_flag; |
Denis Vlasenko | 5625415 | 2006-10-07 16:24:46 +0000 | [diff] [blame] | 62 | size_t oc = 0, ibs = 512, obs = 512; |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 63 | ssize_t n, w; |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 64 | off_t seek = 0, skip = 0, count = OFF_T_MAX; |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 65 | int oflag, ifd, ofd; |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 66 | const char *infile = NULL, *outfile = NULL; |
| 67 | char *ibuf, *obuf; |
Eric Andersen | ddea368 | 2000-11-29 22:33:02 +0000 | [diff] [blame] | 68 | |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 69 | if (ENABLE_FEATURE_DD_SIGNAL_HANDLING) { |
Rob Landley | c559817 | 2006-05-02 22:44:04 +0000 | [diff] [blame] | 70 | struct sigaction sa; |
| 71 | |
| 72 | memset(&sa, 0, sizeof(sa)); |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 73 | sa.sa_handler = dd_output_status; |
Rob Landley | c559817 | 2006-05-02 22:44:04 +0000 | [diff] [blame] | 74 | sa.sa_flags = SA_RESTART; |
| 75 | sigemptyset(&sa.sa_mask); |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 76 | sigaction(SIGUSR1, &sa, 0); |
Rob Landley | c559817 | 2006-05-02 22:44:04 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 79 | for (n = 1; n < argc; n++) { |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 80 | char *arg = argv[n]; |
| 81 | /* Must fit into positive ssize_t */ |
| 82 | if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("ibs=", arg, 4)) |
| 83 | ibs = xatoul_range_sfx(arg+4, 0, ((size_t)-1L)/2, dd_suffixes); |
| 84 | else if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("obs=", arg, 4)) |
| 85 | obs = xatoul_range_sfx(arg+4, 0, ((size_t)-1L)/2, dd_suffixes); |
| 86 | else if (!strncmp("bs=", arg, 3)) |
| 87 | ibs = obs = xatoul_range_sfx(arg+3, 0, ((size_t)-1L)/2, dd_suffixes); |
Denis Vlasenko | 5dd27b1 | 2006-11-25 14:46:21 +0000 | [diff] [blame] | 88 | /* These can be large: */ |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 89 | else if (!strncmp("count=", arg, 6)) |
Denis Vlasenko | 5dd27b1 | 2006-11-25 14:46:21 +0000 | [diff] [blame] | 90 | count = XATOU_SFX(arg+6, dd_suffixes); |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 91 | else if (!strncmp("seek=", arg, 5)) |
Denis Vlasenko | 5dd27b1 | 2006-11-25 14:46:21 +0000 | [diff] [blame] | 92 | seek = XATOU_SFX(arg+5, dd_suffixes); |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 93 | else if (!strncmp("skip=", arg, 5)) |
Denis Vlasenko | 5dd27b1 | 2006-11-25 14:46:21 +0000 | [diff] [blame] | 94 | skip = XATOU_SFX(arg+5, dd_suffixes); |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 95 | |
| 96 | else if (!strncmp("if=", arg, 3)) |
| 97 | infile = arg+3; |
| 98 | else if (!strncmp("of=", arg, 3)) |
| 99 | outfile = arg+3; |
| 100 | else if (ENABLE_FEATURE_DD_IBS_OBS && !strncmp("conv=", arg, 5)) { |
| 101 | arg += 5; |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 102 | while (1) { |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 103 | if (!strncmp("notrunc", arg, 7)) { |
Denis Vlasenko | 5625415 | 2006-10-07 16:24:46 +0000 | [diff] [blame] | 104 | flags &= ~trunc_flag; |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 105 | arg += 7; |
| 106 | } else if (!strncmp("sync", arg, 4)) { |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 107 | flags |= sync_flag; |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 108 | arg += 4; |
| 109 | } else if (!strncmp("noerror", arg, 7)) { |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 110 | flags |= noerror; |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 111 | arg += 7; |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 112 | } else { |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 113 | bb_error_msg_and_die(bb_msg_invalid_arg, arg, "conv"); |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 114 | } |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 115 | if (arg[0] == '\0') break; |
| 116 | if (*arg++ != ',') bb_show_usage(); |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 117 | } |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 118 | } else |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 119 | bb_show_usage(); |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 120 | } |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 121 | |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 122 | ibuf = obuf = xmalloc(ibs); |
| 123 | if (ibs != obs) { |
| 124 | flags |= twobufs_flag; |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 125 | obuf = xmalloc(obs); |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 126 | } |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 127 | |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 128 | if (infile != NULL) |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 129 | ifd = xopen(infile, O_RDONLY); |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 130 | else { |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 131 | ifd = STDIN_FILENO; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 132 | infile = bb_msg_standard_input; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 135 | if (outfile != NULL) { |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 136 | oflag = O_WRONLY | O_CREAT; |
Matt Kraai | c9acf8c | 2001-01-17 00:21:05 +0000 | [diff] [blame] | 137 | |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 138 | if (!seek && (flags & trunc_flag)) |
Matt Kraai | c9acf8c | 2001-01-17 00:21:05 +0000 | [diff] [blame] | 139 | oflag |= O_TRUNC; |
| 140 | |
Denis Vlasenko | cf749bc | 2006-11-26 15:45:17 +0000 | [diff] [blame] | 141 | ofd = xopen(outfile, oflag); |
Matt Kraai | c9acf8c | 2001-01-17 00:21:05 +0000 | [diff] [blame] | 142 | |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 143 | if (seek && (flags & trunc_flag)) { |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 144 | if (ftruncate(ofd, seek * obs) < 0) { |
Matt Kraai | eb83478 | 2002-02-05 15:28:54 +0000 | [diff] [blame] | 145 | struct stat st; |
| 146 | |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 147 | if (fstat(ofd, &st) < 0 || S_ISREG(st.st_mode) || |
| 148 | S_ISDIR(st.st_mode)) |
| 149 | goto die_outfile; |
Matt Kraai | eb83478 | 2002-02-05 15:28:54 +0000 | [diff] [blame] | 150 | } |
Matt Kraai | c9acf8c | 2001-01-17 00:21:05 +0000 | [diff] [blame] | 151 | } |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 152 | } else { |
| 153 | ofd = STDOUT_FILENO; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 154 | outfile = bb_msg_standard_output; |
Erik Andersen | e49d5ec | 2000-02-08 19:58:47 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 157 | if (skip) { |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 158 | if (lseek(ifd, skip * ibs, SEEK_CUR) < 0) { |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 159 | while (skip-- > 0) { |
| 160 | n = safe_read(ifd, ibuf, ibs); |
| 161 | if (n < 0) |
| 162 | bb_perror_msg_and_die("%s", infile); |
| 163 | if (n == 0) |
| 164 | break; |
| 165 | } |
Glenn L McGrath | eaed78a | 2002-11-28 11:05:28 +0000 | [diff] [blame] | 166 | } |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 167 | } |
Eric Andersen | ddea368 | 2000-11-29 22:33:02 +0000 | [diff] [blame] | 168 | |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 169 | if (seek) { |
Denis Vlasenko | 7039a66 | 2006-10-08 17:54:47 +0000 | [diff] [blame] | 170 | if (lseek(ofd, seek * obs, SEEK_CUR) < 0) |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 171 | goto die_outfile; |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 172 | } |
Eric Andersen | ddea368 | 2000-11-29 22:33:02 +0000 | [diff] [blame] | 173 | |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 174 | while (in_full + in_part != count) { |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 175 | if (flags & noerror) { |
Eric Andersen | ef38b39 | 2002-04-27 01:31:43 +0000 | [diff] [blame] | 176 | /* Pre-zero the buffer when doing the noerror thing */ |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 177 | memset(ibuf, '\0', ibs); |
Eric Andersen | ef38b39 | 2002-04-27 01:31:43 +0000 | [diff] [blame] | 178 | } |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 179 | |
| 180 | n = safe_read(ifd, ibuf, ibs); |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 181 | if (n == 0) |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 182 | break; |
Eric Andersen | ef38b39 | 2002-04-27 01:31:43 +0000 | [diff] [blame] | 183 | if (n < 0) { |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 184 | if (flags & noerror) { |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 185 | n = ibs; |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 186 | bb_perror_msg("%s", infile); |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 187 | } else |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 188 | bb_perror_msg_and_die("%s", infile); |
Eric Andersen | ef38b39 | 2002-04-27 01:31:43 +0000 | [diff] [blame] | 189 | } |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 190 | if ((size_t)n == ibs) |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 191 | in_full++; |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 192 | else { |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 193 | in_part++; |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 194 | if (flags & sync_flag) { |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 195 | memset(ibuf + n, '\0', ibs - n); |
| 196 | n = ibs; |
| 197 | } |
Glenn L McGrath | eaed78a | 2002-11-28 11:05:28 +0000 | [diff] [blame] | 198 | } |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 199 | if (flags & twobufs_flag) { |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 200 | char *tmp = ibuf; |
| 201 | while (n) { |
| 202 | size_t d = obs - oc; |
| 203 | |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 204 | if (d > n) |
| 205 | d = n; |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 206 | memcpy(obuf + oc, tmp, d); |
| 207 | n -= d; |
| 208 | tmp += d; |
| 209 | oc += d; |
| 210 | if (oc == obs) { |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 211 | w = full_write_or_warn(ofd, obuf, obs, outfile); |
| 212 | if (w < 0) goto out_status; |
| 213 | if (w == obs) |
| 214 | out_full++; |
| 215 | else if (w > 0) |
| 216 | out_part++; |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 217 | oc = 0; |
| 218 | } |
| 219 | } |
Glenn L McGrath | eaed78a | 2002-11-28 11:05:28 +0000 | [diff] [blame] | 220 | } else { |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 221 | w = full_write_or_warn(ofd, ibuf, n, outfile); |
| 222 | if (w < 0) goto out_status; |
| 223 | if (w == obs) |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 224 | out_full++; |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 225 | else if (w > 0) |
Bernhard Reutner-Fischer | 73561cc | 2006-08-28 23:31:54 +0000 | [diff] [blame] | 226 | out_part++; |
Glenn L McGrath | eaed78a | 2002-11-28 11:05:28 +0000 | [diff] [blame] | 227 | } |
Glenn L McGrath | f0b073f | 2000-09-11 00:32:13 +0000 | [diff] [blame] | 228 | } |
Denis Vlasenko | 9213a9e | 2006-09-17 16:28:10 +0000 | [diff] [blame] | 229 | |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 230 | if (ENABLE_FEATURE_DD_IBS_OBS && oc) { |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 231 | w = full_write_or_warn(ofd, obuf, oc, outfile); |
| 232 | if (w < 0) goto out_status; |
| 233 | if (w > 0) |
| 234 | out_part++; |
Rob Landley | 2686d3b | 2006-05-16 16:52:12 +0000 | [diff] [blame] | 235 | } |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 236 | if (close(ifd) < 0) { |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 237 | bb_perror_msg_and_die("%s", infile); |
Glenn L McGrath | eaed78a | 2002-11-28 11:05:28 +0000 | [diff] [blame] | 238 | } |
Matt Kraai | 3eeab3b | 2001-12-07 16:27:37 +0000 | [diff] [blame] | 239 | |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 240 | if (close(ofd) < 0) { |
| 241 | die_outfile: |
Manuel Novoa III | cad5364 | 2003-03-19 09:13:01 +0000 | [diff] [blame] | 242 | bb_perror_msg_and_die("%s", outfile); |
Glenn L McGrath | eaed78a | 2002-11-28 11:05:28 +0000 | [diff] [blame] | 243 | } |
Denis Vlasenko | 3b8ff68 | 2006-10-31 15:55:56 +0000 | [diff] [blame] | 244 | out_status: |
Rob Landley | c559817 | 2006-05-02 22:44:04 +0000 | [diff] [blame] | 245 | dd_output_status(0); |
Matt Kraai | 24ac017 | 2000-12-18 21:38:57 +0000 | [diff] [blame] | 246 | |
Matt Kraai | 3e856ce | 2000-12-01 02:55:13 +0000 | [diff] [blame] | 247 | return EXIT_SUCCESS; |
Eric Andersen | 3cf52d1 | 1999-10-12 22:26:06 +0000 | [diff] [blame] | 248 | } |