From 29eced50687dd8a39dafe704102ae09ea8e8533a Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 7 Feb 2013 20:51:29 +0100 Subject: Add public function gpgme_io_writen. * src/gpgme.c (gpgme_io_read): New. -- This is a writen style variant for gpgme_io_write. It is often easier to use this one in passphrase and edit callbacks. --- src/gpgme.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src/gpgme.c') diff --git a/src/gpgme.c b/src/gpgme.c index 86099d60..79895db2 100644 --- a/src/gpgme.c +++ b/src/gpgme.c @@ -634,6 +634,30 @@ gpgme_io_write (int fd, const void *buffer, size_t count) return TRACE_SYSRES (ret); } +/* This function provides access to the internal write function. It + is to be used by user callbacks to return data to gpgme. See + gpgme_passphrase_cb_t and gpgme_edit_cb_t. Note that this is a + variant of gpgme_io_write which guarantees that all COUNT bytes are + written or an error is return. Returns: 0 on success or -1 on + error and the sets errno. */ +int +gpgme_io_writen (int fd, const void *buffer, size_t count) +{ + int ret = 0; + TRACE_BEG2 (DEBUG_GLOBAL, "gpgme_io_writen", fd, + "buffer=%p, count=%u", buffer, count); + while (count) + { + ret = _gpgme_io_write (fd, buffer, count); + if (ret < 0) + break; + buffer += ret; + count -= ret; + ret = 0; + } + return TRACE_SYSRES (ret); +} + /* This function returns the callback function for I/O. */ void -- cgit v1.2.3