summaryrefslogtreecommitdiff
path: root/usage.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-01-11 09:02:03 -0500
committerJunio C Hamano <gitster@pobox.com>2017-01-11 13:52:00 -0800
commitb5a9e435c6dfb40df0a27521c1c6590c8f68ffb2 (patch)
tree63ef05a347ed0a57a03762c5af7d27c799b4b2fb /usage.c
parent0b65a8dbdb38962e700ee16776a3042beb489060 (diff)
downloadgit-b5a9e435c6dfb40df0a27521c1c6590c8f68ffb2.tar.gz
Revert "vreportf: avoid intermediate buffer"
This reverts commit f4c3edc0b156362a92bf9de4f0ec794e90a757fc. The purpose of that commit was to let us write errors of arbitrary length to stderr by skipping the intermediate buffer and sending our varargs straight to fprintf. That works, but it comes with a downside: we do not get access to the varargs before they are sent to stderr. On balance, it's not a good tradeoff. Error messages larger than our 4K buffer are quite uncommon, and we've lost the ability to make any modifications to the output (e.g., to remove non-printable characters). The only way to have both would be one of: 1. Write into a dynamic buffer. But this is a bad idea for a low-level function that may be called when malloc() has failed. 2. Do our own printf-format varargs parsing. This is too complex to be worth the trouble. Let's just revert that change and go back to a fixed buffer. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'usage.c')
-rw-r--r--usage.c15
1 files changed, 3 insertions, 12 deletions
diff --git a/usage.c b/usage.c
index 82ff13163b..e4fa6d2f03 100644
--- a/usage.c
+++ b/usage.c
@@ -7,21 +7,13 @@
#include "cache.h"
static FILE *error_handle;
-static int tweaked_error_buffering;
void vreportf(const char *prefix, const char *err, va_list params)
{
+ char msg[4096];
FILE *fh = error_handle ? error_handle : stderr;
-
- fflush(fh);
- if (!tweaked_error_buffering) {
- setvbuf(fh, NULL, _IOLBF, 0);
- tweaked_error_buffering = 1;
- }
-
- fputs(prefix, fh);
- vfprintf(fh, err, params);
- fputc('\n', fh);
+ vsnprintf(msg, sizeof(msg), err, params);
+ fprintf(fh, "%s%s\n", prefix, msg);
}
static NORETURN void usage_builtin(const char *err, va_list params)
@@ -78,7 +70,6 @@ void set_die_is_recursing_routine(int (*routine)(void))
void set_error_handle(FILE *fh)
{
error_handle = fh;
- tweaked_error_buffering = 0;
}
void NORETURN usagef(const char *err, ...)