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