aboutsummaryrefslogtreecommitdiffstats
path: root/common/miscellaneous.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2014-08-26 15:47:22 +0000
committerWerner Koch <[email protected]>2014-08-26 15:47:54 +0000
commit519305feb888b529c005b40445d041a088a2f8fc (patch)
tree74994a5b568e059982ca83a0daa8b7d96035355d /common/miscellaneous.c
parentgpg: Allow for positional parameters in the passphrase prompt. (diff)
downloadgnupg-519305feb888b529c005b40445d041a088a2f8fc.tar.gz
gnupg-519305feb888b529c005b40445d041a088a2f8fc.zip
Switch to the libgpg-error provided estream.
* configure.ac (NEED_GPG_ERROR_VERSION): Reguire 1.14. (GPGRT_ENABLE_ES_MACROS): Define. (estream_INIT): Remove. * m4/estream.m4: Remove. * common/estream-printf.c, common/estream-printf.h: Remove. * common/estream.c, common/estream.h: Remove. * common/init.c (_init_common_subsystems): Call gpgrt initialization.
Diffstat (limited to 'common/miscellaneous.c')
-rw-r--r--common/miscellaneous.c45
1 files changed, 43 insertions, 2 deletions
diff --git a/common/miscellaneous.c b/common/miscellaneous.c
index 31c4e3811..862e952ea 100644
--- a/common/miscellaneous.c
+++ b/common/miscellaneous.c
@@ -145,6 +145,47 @@ print_fname_stdin (const char *s)
}
+static int
+do_print_utf8_buffer (estream_t stream,
+ const void *buffer, size_t length,
+ const char *delimiters, size_t *bytes_written)
+{
+ const char *p = buffer;
+ size_t i;
+
+ /* We can handle plain ascii simpler, so check for it first. */
+ for (i=0; i < length; i++ )
+ {
+ if ( (p[i] & 0x80) )
+ break;
+ }
+ if (i < length)
+ {
+ int delim = delimiters? *delimiters : 0;
+ char *buf;
+ int ret;
+
+ /*(utf8 conversion already does the control character quoting). */
+ buf = utf8_to_native (p, length, delim);
+ if (bytes_written)
+ *bytes_written = strlen (buf);
+ ret = es_fputs (buf, stream);
+ xfree (buf);
+ return ret == EOF? ret : (int)i;
+ }
+ else
+ return es_write_sanitized (stream, p, length, delimiters, bytes_written);
+}
+
+
+void
+print_utf8_buffer3 (estream_t stream, const void *p, size_t n,
+ const char *delim)
+{
+ do_print_utf8_buffer (stream, p, n, delim, NULL);
+}
+
+
void
print_utf8_buffer2 (estream_t stream, const void *p, size_t n, int delim)
{
@@ -152,14 +193,14 @@ print_utf8_buffer2 (estream_t stream, const void *p, size_t n, int delim)
tmp[0] = delim;
tmp[1] = 0;
- es_write_sanitized_utf8_buffer (stream, p, n, tmp, NULL);
+ do_print_utf8_buffer (stream, p, n, tmp, NULL);
}
void
print_utf8_buffer (estream_t stream, const void *p, size_t n)
{
- es_write_sanitized_utf8_buffer (stream, p, n, NULL, NULL);
+ do_print_utf8_buffer (stream, p, n, NULL, NULL);
}
/* Write LENGTH bytes of BUFFER to FP as a hex encoded string.