Coverage Report

Created: 2025-07-11 06:11

/src/gdbm/tools/err.c
Line
Count
Source (jump to first uncovered line)
1
/* This file is part of GDBM, the GNU data base manager.
2
   Copyright (C) 2011-2025 Free Software Foundation, Inc.
3
4
   GDBM is free software; you can redistribute it and/or modify
5
   it under the terms of the GNU General Public License as published by
6
   the Free Software Foundation; either version 3, or (at your option)
7
   any later version.
8
9
   GDBM is distributed in the hope that it will be useful,
10
   but WITHOUT ANY WARRANTY; without even the implied warranty of
11
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
   GNU General Public License for more details.
13
14
   You should have received a copy of the GNU General Public License
15
   along with GDBM. If not, see <http://www.gnu.org/licenses/>.   */
16
17
# include "autoconf.h"
18
# include "gdbm.h"
19
# include "gdbmapp.h"
20
# include <stdio.h>
21
# include <errno.h>
22
# include <string.h>
23
24
static void
25
prerror (const char *fmt, va_list ap, const char *diag, const char *sysdiag)
26
0
{
27
0
  fprintf (stderr, "%s: ", progname);
28
0
  vfprintf (stderr, fmt, ap);
29
0
  if (diag)
30
0
    fprintf (stderr, ": %s", diag);
31
0
  if (sysdiag)
32
0
    fprintf (stderr, ": %s", sysdiag);
33
0
  fputc ('\n', stderr);
34
0
}
35
36
void
37
verror (const char *fmt, va_list ap)
38
0
{
39
0
  prerror (fmt, ap, NULL, NULL);
40
0
}
41
42
void
43
error (const char *fmt, ...)
44
0
{
45
0
  va_list ap;
46
0
  va_start (ap, fmt);
47
0
  verror (fmt, ap);
48
0
  va_end (ap);
49
0
}
50
51
void
52
sys_perror (int code, const char *fmt, ...)
53
0
{
54
0
  va_list ap;
55
0
  va_start (ap, fmt);
56
0
  prerror (fmt, ap, strerror (code), NULL);
57
0
  va_end (ap);
58
0
}
59
60
void
61
gdbm_perror (const char *fmt, ...)
62
0
{
63
0
  va_list ap;
64
0
  va_start (ap, fmt);
65
0
  prerror (fmt, ap, gdbm_strerror (gdbm_errno),
66
0
     gdbm_syserr[gdbm_errno] ? strerror (errno) : NULL);
67
0
  va_end (ap);
68
0
}
69