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