summaryrefslogtreecommitdiff
path: root/tools/err.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2021-11-18 15:46:34 +0200
committerSergey Poznyakoff <gray@gnu.org>2021-11-20 08:59:03 +0200
commitd38991be3ee99b158e889e78439fc21723154767 (patch)
tree54bf2d7f4e938d3a5ca1b90782a9cfbe626438cb /tools/err.c
parent669d541702fa39cd45ceab1eb333cb100c0d08ac (diff)
downloadgdbm-d38991be3ee99b158e889e78439fc21723154767.tar.gz
Rearrange the directory structure
Sources for the libgdbm library reside in src/. Sources for building accompanying tools are moved to the tools/ subdirectory.
Diffstat (limited to 'tools/err.c')
-rw-r--r--tools/err.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/tools/err.c b/tools/err.c
new file mode 100644
index 0000000..19ba6ef
--- /dev/null
+++ b/tools/err.c
@@ -0,0 +1,69 @@
+/* This file is part of GDBM, the GNU data base manager.
+ Copyright (C) 2011-2021 Free Software Foundation, Inc.
+
+ GDBM is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3, or (at your option)
+ any later version.
+
+ GDBM is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GDBM. If not, see <http://www.gnu.org/licenses/>. */
+
+# include "autoconf.h"
+# include "gdbm.h"
+# include "gdbmapp.h"
+# include <stdio.h>
+# include <errno.h>
+# include <string.h>
+
+static void
+prerror (const char *fmt, va_list ap, const char *diag, const char *sysdiag)
+{
+ fprintf (stderr, "%s: ", progname);
+ vfprintf (stderr, fmt, ap);
+ if (diag)
+ fprintf (stderr, ": %s", diag);
+ if (sysdiag)
+ fprintf (stderr, ": %s", sysdiag);
+ fputc ('\n', stderr);
+}
+
+void
+verror (const char *fmt, va_list ap)
+{
+ prerror (fmt, ap, NULL, NULL);
+}
+
+void
+error (const char *fmt, ...)
+{
+ va_list ap;
+ va_start (ap, fmt);
+ verror (fmt, ap);
+ va_end (ap);
+}
+
+void
+sys_perror (int code, const char *fmt, ...)
+{
+ va_list ap;
+ va_start (ap, fmt);
+ prerror (fmt, ap, strerror (code), NULL);
+ va_end (ap);
+}
+
+void
+gdbm_perror (const char *fmt, ...)
+{
+ va_list ap;
+ va_start (ap, fmt);
+ prerror (fmt, ap, gdbm_strerror (gdbm_errno),
+ gdbm_syserr[gdbm_errno] ? strerror (errno) : NULL);
+ va_end (ap);
+}
+