summaryrefslogtreecommitdiff
path: root/src/bin/psql/print.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/bin/psql/print.c')
-rw-r--r--src/bin/psql/print.c26
1 files changed, 21 insertions, 5 deletions
diff --git a/src/bin/psql/print.c b/src/bin/psql/print.c
index d62b46d0103..1d73fd5790f 100644
--- a/src/bin/psql/print.c
+++ b/src/bin/psql/print.c
@@ -3,7 +3,7 @@
*
* Copyright (c) 2000-2010, PostgreSQL Global Development Group
*
- * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.124 2010/03/01 21:27:26 heikki Exp $
+ * $PostgreSQL: pgsql/src/bin/psql/print.c,v 1.125 2010/05/08 16:39:52 tgl Exp $
*/
#include "postgres_fe.h"
@@ -252,6 +252,20 @@ format_numeric_locale(const char *my_str)
}
+/*
+ * fputnbytes: print exactly N bytes to a file
+ *
+ * Think not to use fprintf with a %.*s format for this. Some machines
+ * believe %s's precision is measured in characters, others in bytes.
+ */
+static void
+fputnbytes(FILE *f, const char *str, size_t n)
+{
+ while (n-- > 0)
+ fputc(*str++, f);
+}
+
+
/*************************/
/* Unaligned text */
/*************************/
@@ -913,14 +927,16 @@ print_aligned_text(const printTableContent *cont, FILE *fout)
{
/* spaces first */
fprintf(fout, "%*s", width_wrap[j] - chars_to_output, "");
- fprintf(fout, "%.*s", bytes_to_output,
- this_line->ptr + bytes_output[j]);
+ fputnbytes(fout,
+ this_line->ptr + bytes_output[j],
+ bytes_to_output);
}
else /* Left aligned cell */
{
/* spaces second */
- fprintf(fout, "%.*s", bytes_to_output,
- this_line->ptr + bytes_output[j]);
+ fputnbytes(fout,
+ this_line->ptr + bytes_output[j],
+ bytes_to_output);
}
bytes_output[j] += bytes_to_output;