aboutsummaryrefslogtreecommitdiff
path: root/usage.c
diff options
context:
space:
mode:
authorJunio C Hamano <gitster@pobox.com>2015-08-25 14:57:06 -0700
committerJunio C Hamano <gitster@pobox.com>2015-08-25 14:57:06 -0700
commit1302c9f514686e32065130ec9a80eb0db224e819 (patch)
treea9891d1a8906165ccabc6e005da5eb4fda1306d7 /usage.c
parentb590720f2cd3638930847f5abf646275caf8d334 (diff)
parentf4c3edc0b156362a92bf9de4f0ec794e90a757fc (diff)
downloadgit-1302c9f514686e32065130ec9a80eb0db224e819.tar.xz
Merge branch 'jk/long-error-messages'
The codepath to produce error messages had a hard-coded limit to the size of the message, primarily to avoid memory allocation while calling die(). * jk/long-error-messages: vreportf: avoid intermediate buffer vreportf: report to arbitrary filehandles
Diffstat (limited to 'usage.c')
-rw-r--r--usage.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/usage.c b/usage.c
index ed146453ca..82ff13163b 100644
--- a/usage.c
+++ b/usage.c
@@ -6,23 +6,22 @@
#include "git-compat-util.h"
#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];
- vsnprintf(msg, sizeof(msg), err, params);
- fprintf(stderr, "%s%s\n", prefix, msg);
-}
+ FILE *fh = error_handle ? error_handle : stderr;
-void vwritef(int fd, const char *prefix, const char *err, va_list params)
-{
- char msg[4096];
- int len = vsnprintf(msg, sizeof(msg), err, params);
- if (len > sizeof(msg))
- len = sizeof(msg);
+ fflush(fh);
+ if (!tweaked_error_buffering) {
+ setvbuf(fh, NULL, _IOLBF, 0);
+ tweaked_error_buffering = 1;
+ }
- write_in_full(fd, prefix, strlen(prefix));
- write_in_full(fd, msg, len);
- write_in_full(fd, "\n", 1);
+ fputs(prefix, fh);
+ vfprintf(fh, err, params);
+ fputc('\n', fh);
}
static NORETURN void usage_builtin(const char *err, va_list params)
@@ -76,6 +75,12 @@ void set_die_is_recursing_routine(int (*routine)(void))
die_is_recursing = routine;
}
+void set_error_handle(FILE *fh)
+{
+ error_handle = fh;
+ tweaked_error_buffering = 0;
+}
+
void NORETURN usagef(const char *err, ...)
{
va_list params;