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.
This commit is contained in:
Werner Koch 2013-02-07 20:51:29 +01:00
parent 51fd6d8292
commit 29eced5068
5 changed files with 158 additions and 129 deletions

View File

@ -2374,9 +2374,10 @@ previous attempts failed, then @var{prev_was_bad} is 1, otherwise it
will be 0.
The user must write the passphrase, followed by a newline character,
to the file descriptor @var{fd}. If the user returns 0 indicating
success, the user must at least write a newline character before
returning from the callback.
to the file descriptor @var{fd}. The function @code{gpgme_io_writen}
should be used for the write operation. Note that if the user returns
0 to indicate success, the user must at least write a newline
character before returning from the callback.
If an error occurs, return the corresponding @code{gpgme_error_t}
value. You can use the error code @code{GPG_ERR_CANCELED} to abort

View File

@ -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

View File

@ -204,5 +204,6 @@ EXPORTS
gpgme_set_global_flag @156
gpgme_io_writen @157
; END

View File

@ -1022,6 +1022,7 @@ void gpgme_get_io_cbs (gpgme_ctx_t ctx, gpgme_io_cbs_t io_cbs);
gpgme_passphrase_cb_t and gpgme_edit_cb_t. */
ssize_t gpgme_io_read (int fd, void *buffer, size_t count);
ssize_t gpgme_io_write (int fd, const void *buffer, size_t count);
int gpgme_io_writen (int fd, const void *buffer, size_t count);
/* Process the pending operation and, if HANG is non-zero, wait for
the pending operation to finish. */

View File

@ -81,6 +81,8 @@ GPGME_1.1 {
gpgme_op_passwd;
gpgme_set_global_flag;
gpgme_io_writen;
};