From 4491ef0a9a15d3b307d1ade37ff620ef9fcb2478 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Tue, 13 Sep 2016 20:46:41 +0200 Subject: [PATCH] tests: Use gpgme_io_write in passhrase callbacks. * tests/gpg/t-support.h (passphrase_cb): Use gpgme_io_write. * tests/gpgsm/t-support.h (passphrase_cb): Ditto. * tests/run-support.h (passphrase_cb): Ditto. Signed-off-by: Werner Koch --- tests/gpg/t-support.h | 16 +++++++--------- tests/gpgsm/t-support.h | 9 +++++++-- tests/run-support.h | 16 +++++++--------- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/tests/gpg/t-support.h b/tests/gpg/t-support.h index 6a18b5cb..7a0b9f9b 100644 --- a/tests/gpg/t-support.h +++ b/tests/gpg/t-support.h @@ -76,27 +76,25 @@ gpgme_error_t passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info, int last_was_bad, int fd) { -#ifdef HAVE_W32_SYSTEM - DWORD written; - WriteFile ((HANDLE) fd, "abc\n", 4, &written, 0); -#else int res; - char *pass = "abc\n"; + char pass[] = "abc\n"; int passlen = strlen (pass); int off = 0; + (void)opaque; + (void)uid_hint; + (void)passphrase_info; + (void)last_was_bad; + do { - res = write (fd, &pass[off], passlen - off); + res = gpgme_io_write (fd, &pass[off], passlen - off); if (res > 0) off += res; } while (res > 0 && off != passlen); return off == passlen ? 0 : gpgme_error_from_errno (errno); -#endif - - return 0; } diff --git a/tests/gpgsm/t-support.h b/tests/gpgsm/t-support.h index cc1a7db9..ae3ad1f6 100644 --- a/tests/gpgsm/t-support.h +++ b/tests/gpgsm/t-support.h @@ -63,13 +63,18 @@ passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info, int last_was_bad, int fd) { int res; - char *pass = "abc\n"; + char pass[] = "abc\n"; int passlen = strlen (pass); int off = 0; + (void)opaque; + (void)uid_hint; + (void)passphrase_info; + (void)last_was_bad; + do { - res = write (fd, &pass[off], passlen - off); + res = gpgme_io_write (fd, &pass[off], passlen - off); if (res > 0) off += res; } diff --git a/tests/run-support.h b/tests/run-support.h index b1aea4be..e4a4f703 100644 --- a/tests/run-support.h +++ b/tests/run-support.h @@ -75,27 +75,25 @@ gpgme_error_t passphrase_cb (void *opaque, const char *uid_hint, const char *passphrase_info, int last_was_bad, int fd) { -#ifdef HAVE_W32_SYSTEM - DWORD written; - WriteFile ((HANDLE) fd, "abc\n", 4, &written, 0); -#else int res; - char *pass = "abc\n"; + char pass[] = "abc\n"; int passlen = strlen (pass); int off = 0; + (void)opaque; + (void)uid_hint; + (void)passphrase_info; + (void)last_was_bad; + do { - res = write (fd, &pass[off], passlen - off); + res = gpgme_io_write (fd, &pass[off], passlen - off); if (res > 0) off += res; } while (res > 0 && off != passlen); return off == passlen ? 0 : gpgme_error_from_errno (errno); -#endif - - return 0; }