Mercurial > projects > libpws
view compat/err.c @ 4:dfd3ddbdb201
Add tests
author | Guido Berhoerster <guido+libpws@berhoerster.name> |
---|---|
date | Fri, 13 May 2016 14:32:44 +0200 |
parents | 97097b4b6bfb |
children |
line wrap: on
line source
/* * 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); }