diff options
Diffstat (limited to 'coreutils/dd.c')
-rw-r--r-- | coreutils/dd.c | 26 |
1 files changed, 13 insertions, 13 deletions
diff --git a/coreutils/dd.c b/coreutils/dd.c index 2d91f77ef..3054ec6ea 100644 --- a/coreutils/dd.c +++ b/coreutils/dd.c | |||
@@ -195,23 +195,15 @@ static void dd_output_status(int UNUSED_PARAM cur_signal) | |||
195 | #endif | 195 | #endif |
196 | } | 196 | } |
197 | 197 | ||
198 | static ssize_t full_write_or_warn(const void *buf, size_t len, | ||
199 | const char *const filename) | ||
200 | { | ||
201 | ssize_t n = full_write(ofd, buf, len); | ||
202 | if (n < 0) | ||
203 | bb_perror_msg("writing '%s'", filename); | ||
204 | return n; | ||
205 | } | ||
206 | |||
207 | static bool write_and_stats(const void *buf, size_t len, size_t obs, | 198 | static bool write_and_stats(const void *buf, size_t len, size_t obs, |
208 | const char *filename) | 199 | const char *filename) |
209 | { | 200 | { |
210 | ssize_t n = full_write_or_warn(buf, len, filename); | 201 | ssize_t n; |
211 | if (n < 0) | 202 | |
212 | return 1; | 203 | n = full_write(ofd, buf, len); |
213 | #if ENABLE_FEATURE_DD_THIRD_STATUS_LINE | 204 | #if ENABLE_FEATURE_DD_THIRD_STATUS_LINE |
214 | G.total_bytes += n; | 205 | if (n > 0) |
206 | G.total_bytes += n; | ||
215 | #endif | 207 | #endif |
216 | if ((size_t)n == obs) { | 208 | if ((size_t)n == obs) { |
217 | G.out_full++; | 209 | G.out_full++; |
@@ -221,6 +213,14 @@ static bool write_and_stats(const void *buf, size_t len, size_t obs, | |||
221 | G.out_part++; | 213 | G.out_part++; |
222 | return 0; | 214 | return 0; |
223 | } | 215 | } |
216 | /* n is < len (and possibly is -1). | ||
217 | * Even if n >= 0, errno is usually set correctly. | ||
218 | * For example, if writing to block device and getting ENOSPC, | ||
219 | * full_write() first sees a short write, then tries to write | ||
220 | * the remainder and gets errno set to ENOSPC. | ||
221 | * It returns n > 0 (the amount which it did write). | ||
222 | */ | ||
223 | bb_perror_msg("error writing '%s'", filename); | ||
224 | return 1; | 224 | return 1; |
225 | } | 225 | } |
226 | 226 | ||