diff options
Diffstat (limited to 'src/err.c')
-rw-r--r-- | src/err.c | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/src/err.c b/src/err.c new file mode 100644 index 0000000..73aaba7 --- /dev/null +++ b/src/err.c @@ -0,0 +1,62 @@ +/* This file is part of vmod-binlog + Copyright (C) 2013 Sergey Poznyakoff + + Vmod-binlog 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. + + Vmod-binlog 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 vmod-binlog. If not, see <http://www.gnu.org/licenses/>. +*/ +#include <config.h> +#include <stdio.h> +#include <stdarg.h> +#include <string.h> +#include "err.h" + +const char *progname; + +void +setprogname(const char *arg) +{ + char *p = strrchr(arg, '/'); + if (p) + progname = p + 1; + else + progname = arg; +} + +void +verror(const char *fmt, va_list ap) +{ + fprintf(stderr, "%s: ", progname); + vfprintf(stderr, fmt, ap); + fputc('\n', stderr); +} + +void +error(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + verror(fmt, ap); + va_end(ap); +} + +void +packerror(const char *fmt, ...) +{ + va_list ap; + + va_start(ap, fmt); + verror(fmt, ap); + va_end(ap); +} + |