Line data Source code
1 : /* t-common.h - Common code for the tests.
2 : * Copyright (C) 2013 g10 Code GmbH
3 : *
4 : * This file is part of libgpg-error.
5 : *
6 : * libgpg-error is free software; you can redistribute it and/or
7 : * modify it under the terms of the GNU Lesser General Public License
8 : * as published by the Free Software Foundation; either version 2.1 of
9 : * the License, or (at your option) any later version.
10 : *
11 : * libgpg-error is distributed in the hope that it will be useful, but
12 : * WITHOUT ANY WARRANTY; without even the implied warranty of
13 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 : * Lesser General Public License for more details.
15 : *
16 : * You should have received a copy of the GNU Lesser General Public
17 : * License along with this program; if not, see <https://www.gnu.org/licenses/>.
18 : */
19 :
20 : #include <stdarg.h>
21 :
22 : #include "../src/gpg-error.h"
23 :
24 : #ifndef PGM
25 : # error Macro PGM not defined.
26 : #endif
27 : #ifndef DIM
28 : # define DIM(array) (sizeof (array) / sizeof (*array))
29 : #endif
30 :
31 :
32 : static int verbose;
33 : static int debug;
34 : static int errorcount;
35 :
36 :
37 : static void
38 0 : die (const char *format, ...)
39 : {
40 : va_list arg_ptr ;
41 :
42 0 : fflush (stdout);
43 : #ifdef HAVE_FLOCKFILE
44 0 : flockfile (stderr);
45 : #endif
46 0 : fprintf (stderr, "%s: ", PGM);
47 0 : va_start (arg_ptr, format) ;
48 0 : vfprintf (stderr, format, arg_ptr);
49 0 : va_end (arg_ptr);
50 0 : if (*format && format[strlen(format)-1] != '\n')
51 0 : putc ('\n', stderr);
52 : #ifdef HAVE_FLOCKFILE
53 0 : funlockfile (stderr);
54 : #endif
55 0 : exit (1);
56 : }
57 :
58 :
59 : static void
60 0 : fail (const char *format, ...)
61 : {
62 : va_list arg_ptr;
63 :
64 0 : fflush (stdout);
65 : #ifdef HAVE_FLOCKFILE
66 0 : flockfile (stderr);
67 : #endif
68 0 : fprintf (stderr, "%s: ", PGM);
69 0 : va_start (arg_ptr, format);
70 0 : vfprintf (stderr, format, arg_ptr);
71 0 : va_end (arg_ptr);
72 0 : if (*format && format[strlen(format)-1] != '\n')
73 0 : putc ('\n', stderr);
74 : #ifdef HAVE_FLOCKFILE
75 0 : funlockfile (stderr);
76 : #endif
77 0 : errorcount++;
78 0 : if (errorcount >= 50)
79 0 : die ("stopped after 50 errors.");
80 0 : }
81 :
82 :
83 : static void
84 550 : show (const char *format, ...)
85 : {
86 : va_list arg_ptr;
87 :
88 550 : if (!verbose)
89 550 : return;
90 : #ifdef HAVE_FLOCKFILE
91 0 : flockfile (stderr);
92 : #endif
93 0 : fprintf (stderr, "%s: ", PGM);
94 0 : va_start (arg_ptr, format);
95 0 : vfprintf (stderr, format, arg_ptr);
96 0 : if (*format && format[strlen(format)-1] != '\n')
97 0 : putc ('\n', stderr);
98 0 : va_end (arg_ptr);
99 : #ifdef HAVE_FLOCKFILE
100 0 : funlockfile (stderr);
101 : #endif
102 : }
|