1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
// -*-c++-*-
/* $Id: err.h,v 1.6 2001/08/22 20:30:24 dm Exp $ */
/*
*
* Copyright (C) 1998 David Mazieres (dm@uun.org)
*
* This program 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 2, or (at
* your option) any later version.
*
* This program 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 this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
*/
#ifndef _ASYNC_ERR_H_
#define _ASYNC_ERR_H_ 1
#include "str.h"
extern bssstr progname;
extern str progdir;
extern void (*fatalhook) ();
extern int errfd;
extern bool fatal_no_destruct;
extern void (*_err_output) (suio *, int);
extern void (*_err_reset_hook) ();
void err_reset ();
void _err_output_sync (suio *, int);
void setprogname (char *argv0);
/* Old-style C functions for compatibility */
extern "C" {
void warn (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
void warnx (const char *fmt, ...) __attribute__ ((format (printf, 1, 2)));
void vwarn (const char *fmt, va_list ap);
void vwarnx (const char *fmt, va_list ap);
void fatal (const char *fmt, ...)
__attribute__ ((noreturn, format (printf, 1, 2)));
void panic (const char *fmt, ...)
__attribute__ ((noreturn, format (printf, 1, 2)));
}
class warnobj : public strbuf {
const int flags;
public:
enum { xflag = 1, fatalflag = 2, panicflag = 4 };
explicit warnobj (int);
~warnobj ();
const warnobj &operator() (const char *fmt, ...) const
__attribute__ ((format (printf, 2, 3)));
};
#define warn warnobj (0)
#define vwarn warn.vfmt
#define warnx warnobj (int (::warnobj::xflag))
#define vwarnx warnx.vfmt
#ifndef __attribute__
/* Fatalobj is just a warnobj with a noreturn destructor. */
class fatalobj : public warnobj {
public:
explicit fatalobj (int f) : warnobj (f) {}
~fatalobj () __attribute__ ((noreturn));
};
#else /* __attribute__ */
# define fatalobj warnobj
#endif /* __attribute__ */
#define fatal fatalobj (int (::warnobj::fatalflag))
#define panic fatalobj (int (::warnobj::panicflag)) ("%s\n", __BACKTRACE__)
#endif /* !_ASYNC_ERR_H_ */
|