diff compat/err.c @ 2:97097b4b6bfb

Add pwsdump utility The pwsdum utility can dump PasswordSafe database files to a plaintext format and convert this format back into a PasswordSafe database.
author Guido Berhoerster <guido+libpws@berhoerster.name>
date Wed, 01 Apr 2015 14:57:57 +0200
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/compat/err.c	Wed Apr 01 14:57:57 2015 +0200
@@ -0,0 +1,113 @@
+/*
+ * Copyright (C) 2011 Guido Berhoerster <guido+libpws@berhoerster.name>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
+ * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
+ * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
+ * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
+ * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <errno.h>
+
+#include "pws-compat.h"
+
+void
+vwarn(const char *fmt, va_list args)
+{
+	int	old_errno = errno;
+
+	fprintf(stderr, "%s: ", getprogname());
+	if (fmt != NULL) {
+		vfprintf(stderr, fmt, args);
+		fprintf(stderr, ": ");
+	}
+	fprintf(stderr, "%s\n", strerror(old_errno));
+	errno = old_errno;
+}
+
+void
+vwarnx(const char *fmt, va_list args)
+{
+	fprintf(stderr, "%s: ", getprogname());
+	if (fmt != NULL) {
+		vfprintf(stderr, fmt, args);
+	}
+	fputc('\n', stderr);
+}
+
+void
+verr(int eval, const char *fmt, va_list args)
+{
+	vwarn(fmt, args);
+
+	exit(eval);
+}
+
+void
+verrx(int eval, const char *fmt, va_list args)
+{
+	vwarnx(fmt, args);
+
+	exit(eval);
+}
+
+void
+err(int eval, const char *fmt, ...)
+{
+	va_list	args;
+
+	va_start(args, fmt);
+	vwarn(fmt, args);
+	va_end(args);
+
+	exit(eval);
+}
+
+void
+errx(int eval, const char *fmt, ...)
+{
+	va_list	args;
+
+	va_start(args, fmt);
+	vwarnx(fmt, args);
+	va_end(args);
+
+	exit(eval);
+}
+
+void
+warn(const char *fmt, ...)
+{
+	va_list	args;
+
+	va_start(args, fmt);
+	vwarn(fmt, args);
+	va_end(args);
+}
+
+void
+warnx(const char *fmt, ...)
+{
+	va_list	args;
+
+	va_start(args, fmt);
+	vwarnx(fmt, args);
+	va_end(args);
+}