Line data Source code
1 : /* asshelp2.c - More helper functions for Assuan
2 : * Copyright (C) 2012 Free Software Foundation, Inc.
3 : *
4 : * This file is part of GnuPG.
5 : *
6 : * This file is free software; you can redistribute it and/or modify
7 : * it under the terms of either
8 : *
9 : * - the GNU Lesser General Public License as published by the Free
10 : * Software Foundation; either version 3 of the License, or (at
11 : * your option) any later version.
12 : *
13 : * or
14 : *
15 : * - the GNU General Public License as published by the Free
16 : * Software Foundation; either version 2 of the License, or (at
17 : * your option) any later version.
18 : *
19 : * or both in parallel, as here.
20 : *
21 : * This file is distributed in the hope that it will be useful,
22 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 : * GNU General Public License for more details.
25 : *
26 : * You should have received a copy of the GNU General Public License
27 : * along with this program; if not, see <https://www.gnu.org/licenses/>.
28 : */
29 :
30 : #include <config.h>
31 : #include <stdio.h>
32 : #include <stdlib.h>
33 : #include <string.h>
34 : #include <errno.h>
35 : #include <assuan.h>
36 :
37 : #include "util.h"
38 : #include "asshelp.h"
39 :
40 : /* Helper function to print an assuan status line using a printf
41 : format string. */
42 : gpg_error_t
43 681 : vprint_assuan_status (assuan_context_t ctx,
44 : const char *keyword,
45 : const char *format, va_list arg_ptr)
46 : {
47 : int rc;
48 : char *buf;
49 :
50 681 : rc = gpgrt_vasprintf (&buf, format, arg_ptr);
51 681 : if (rc < 0)
52 0 : return gpg_err_make (default_errsource, gpg_err_code_from_syserror ());
53 681 : rc = assuan_write_status (ctx, keyword, buf);
54 681 : xfree (buf);
55 681 : return rc;
56 : }
57 :
58 :
59 : /* Helper function to print an assuan status line using a printf
60 : format string. */
61 : gpg_error_t
62 267 : print_assuan_status (assuan_context_t ctx,
63 : const char *keyword,
64 : const char *format, ...)
65 : {
66 : va_list arg_ptr;
67 : gpg_error_t err;
68 :
69 267 : va_start (arg_ptr, format);
70 267 : err = vprint_assuan_status (ctx, keyword, format, arg_ptr);
71 267 : va_end (arg_ptr);
72 267 : return err;
73 : }
|