Skip to content

Commit 3098373

Browse files
Deyuan FanUMAHunter
authored andcommitted
print errno when fwrite fails
1 parent 2a97d81 commit 3098373

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

log.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,12 @@ static void filtered_fwrite(FILE *f, const char *in_buf, int in_len, int use_isp
229229
while (in_buf < end) {
230230
if (ob - outbuf >= (int)sizeof outbuf - 10) {
231231
if (fwrite(outbuf, ob - outbuf, 1, f) != 1)
232+
{
233+
int fwrite_errno = errno;
234+
FILE *fp = (f == stderr) ? stdout : stderr;
235+
fprintf(fp, "filtered_fwrite(): fwrite() error: %s [%s]\n", strerror(fwrite_errno), who_am_i());
232236
exit_cleanup(RERR_MESSAGEIO);
237+
}
233238
ob = outbuf;
234239
}
235240
if ((in_buf < end - 4 && *in_buf == '\\' && in_buf[1] == '#'
@@ -242,7 +247,12 @@ static void filtered_fwrite(FILE *f, const char *in_buf, int in_len, int use_isp
242247
if (end_char) /* The "- 10" above means that there is always room for one more char here. */
243248
*ob++ = end_char;
244249
if (ob != outbuf && fwrite(outbuf, ob - outbuf, 1, f) != 1)
250+
{
251+
int fwrite_errno = errno;
252+
FILE *fp = (f == stderr) ? stdout : stderr;
253+
fprintf(fp, "filtered_fwrite(): fwrite() error: %s [%s]\n", strerror(fwrite_errno), who_am_i());
245254
exit_cleanup(RERR_MESSAGEIO);
255+
}
246256
}
247257

248258
/* this is the underlying (unformatted) rsync debugging function. Call

0 commit comments

Comments
 (0)