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