|
Packit |
fc043f |
/* t-common.h - Common code for the tests.
|
|
Packit |
fc043f |
* Copyright (C) 2013 g10 Code GmbH
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* This file is part of libgpg-error.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* libgpg-error is free software; you can redistribute it and/or
|
|
Packit |
fc043f |
* modify it under the terms of the GNU Lesser General Public License
|
|
Packit |
fc043f |
* as published by the Free Software Foundation; either version 2.1 of
|
|
Packit |
fc043f |
* the License, or (at your option) any later version.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* libgpg-error is distributed in the hope that it will be useful, but
|
|
Packit |
fc043f |
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
Packit |
fc043f |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Packit |
fc043f |
* Lesser General Public License for more details.
|
|
Packit |
fc043f |
*
|
|
Packit |
fc043f |
* You should have received a copy of the GNU Lesser General Public
|
|
Packit |
fc043f |
* License along with this program; if not, see <https://www.gnu.org/licenses/>.
|
|
Packit |
fc043f |
*/
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#include <stdarg.h>
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#include "../src/gpg-error.h"
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
#ifndef PGM
|
|
Packit |
fc043f |
# error Macro PGM not defined.
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
#ifndef DIM
|
|
Packit |
fc043f |
# define DIM(array) (sizeof (array) / sizeof (*array))
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
static int verbose;
|
|
Packit |
fc043f |
static int debug;
|
|
Packit |
fc043f |
static int errorcount;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
static void
|
|
Packit |
fc043f |
die (const char *format, ...)
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
va_list arg_ptr ;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
fflush (stdout);
|
|
Packit |
fc043f |
#ifdef HAVE_FLOCKFILE
|
|
Packit |
fc043f |
flockfile (stderr);
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
fprintf (stderr, "%s: ", PGM);
|
|
Packit |
fc043f |
va_start (arg_ptr, format) ;
|
|
Packit |
fc043f |
vfprintf (stderr, format, arg_ptr);
|
|
Packit |
fc043f |
va_end (arg_ptr);
|
|
Packit |
fc043f |
if (*format && format[strlen(format)-1] != '\n')
|
|
Packit |
fc043f |
putc ('\n', stderr);
|
|
Packit |
fc043f |
#ifdef HAVE_FLOCKFILE
|
|
Packit |
fc043f |
funlockfile (stderr);
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
exit (1);
|
|
Packit |
fc043f |
}
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
static void
|
|
Packit |
fc043f |
fail (const char *format, ...)
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
va_list arg_ptr;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
fflush (stdout);
|
|
Packit |
fc043f |
#ifdef HAVE_FLOCKFILE
|
|
Packit |
fc043f |
flockfile (stderr);
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
fprintf (stderr, "%s: ", PGM);
|
|
Packit |
fc043f |
va_start (arg_ptr, format);
|
|
Packit |
fc043f |
vfprintf (stderr, format, arg_ptr);
|
|
Packit |
fc043f |
va_end (arg_ptr);
|
|
Packit |
fc043f |
if (*format && format[strlen(format)-1] != '\n')
|
|
Packit |
fc043f |
putc ('\n', stderr);
|
|
Packit |
fc043f |
#ifdef HAVE_FLOCKFILE
|
|
Packit |
fc043f |
funlockfile (stderr);
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
errorcount++;
|
|
Packit |
fc043f |
if (errorcount >= 50)
|
|
Packit |
fc043f |
die ("stopped after 50 errors.");
|
|
Packit |
fc043f |
}
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
static void
|
|
Packit |
fc043f |
show (const char *format, ...)
|
|
Packit |
fc043f |
{
|
|
Packit |
fc043f |
va_list arg_ptr;
|
|
Packit |
fc043f |
|
|
Packit |
fc043f |
if (!verbose)
|
|
Packit |
fc043f |
return;
|
|
Packit |
fc043f |
#ifdef HAVE_FLOCKFILE
|
|
Packit |
fc043f |
flockfile (stderr);
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
fprintf (stderr, "%s: ", PGM);
|
|
Packit |
fc043f |
va_start (arg_ptr, format);
|
|
Packit |
fc043f |
vfprintf (stderr, format, arg_ptr);
|
|
Packit |
fc043f |
if (*format && format[strlen(format)-1] != '\n')
|
|
Packit |
fc043f |
putc ('\n', stderr);
|
|
Packit |
fc043f |
va_end (arg_ptr);
|
|
Packit |
fc043f |
#ifdef HAVE_FLOCKFILE
|
|
Packit |
fc043f |
funlockfile (stderr);
|
|
Packit |
fc043f |
#endif
|
|
Packit |
fc043f |
}
|