Skip to content

Commit 351bca2

Browse files
avargitster
authored andcommitted
imap-send.c: use less verbose strbuf_fread() idiom
When looking for things that hardcoded a non-zero "hint" parameter to strbuf_fread() I discovered that since f2561fd (Add git-imap-send, derived from isync 1.0.1., 2006-03-10) we've been passing a hardcoded 4096 in imap-send.c to read stdin. Since we're not doing anything unusual here let's use a less verbose pattern used in a lot of other places (the hint of "0" will default to 8192). We don't need to take a FILE * here either, so we can use "0" instead of "stdin". While we're at it improve the error message if we can't read the input to use error_errno(). Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 670b81a commit 351bca2

File tree

1 file changed

+2
-14
lines changed

1 file changed

+2
-14
lines changed

imap-send.c

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1266,18 +1266,6 @@ static void wrap_in_html(struct strbuf *msg)
12661266
*msg = buf;
12671267
}
12681268

1269-
#define CHUNKSIZE 0x1000
1270-
1271-
static int read_message(FILE *f, struct strbuf *all_msgs)
1272-
{
1273-
do {
1274-
if (strbuf_fread(all_msgs, CHUNKSIZE, f) <= 0)
1275-
break;
1276-
} while (!feof(f));
1277-
1278-
return ferror(f) ? -1 : 0;
1279-
}
1280-
12811269
static int count_messages(struct strbuf *all_msgs)
12821270
{
12831271
int count = 0;
@@ -1582,8 +1570,8 @@ int cmd_main(int argc, const char **argv)
15821570
}
15831571

15841572
/* read the messages */
1585-
if (read_message(stdin, &all_msgs)) {
1586-
fprintf(stderr, "error reading input\n");
1573+
if (strbuf_read(&all_msgs, 0, 0) < 0) {
1574+
error_errno(_("could not read from stdin"));
15871575
return 1;
15881576
}
15891577

0 commit comments

Comments
 (0)