chiark / gitweb /
84a0f8dd6f738883d751aa5865ab8d0bbd843d4d
[mLib] / report.c
1 /* -*-c-*-
2  *
3  * Reporting errors and things
4  *
5  * (c) 1998 Straylight/Edgeware
6  */
7
8 /*----- Licensing notice --------------------------------------------------*
9  *
10  * This file is part of the mLib utilities library.
11  *
12  * mLib is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU Library General Public License as
14  * published by the Free Software Foundation; either version 2 of the
15  * License, or (at your option) any later version.
16  *
17  * mLib is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU Library General Public License for more details.
21  *
22  * You should have received a copy of the GNU Library General Public
23  * License along with mLib; if not, write to the Free
24  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25  * MA 02111-1307, USA.
26  */
27
28 /*----- Header files ------------------------------------------------------*/
29
30 #include <stdarg.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <string.h>
34
35 #include "quis.h"
36 #include "report.h"
37
38 /*----- Functions provided ------------------------------------------------*/
39
40 /* --- @moan@ --- *
41  *
42  * Arguments:   @const char *f@ = a @printf@-style format string
43  *              @...@ = other arguments
44  *
45  * Returns:     ---
46  *
47  * Use:         Reports an error.
48  */
49
50 void moan(const char *f, ...)
51 {
52   va_list ap;
53   va_start(ap, f);
54   fprintf(stderr, "%s: ", QUIS);
55   vfprintf(stderr, f, ap);
56   va_end(ap);
57   putc('\n', stderr);
58 }
59
60 /* --- @die@ --- *
61  *
62  * Arguments:   @int status@ = exit status to return
63  *              @const char *f@ = a @printf@-style format string
64  *              @...@ = other arguments
65  *
66  * Returns:     Never.
67  *
68  * Use:         Reports an error and exits.  Like @moan@ above, only more
69  *              permanent.
70  */
71
72 void die(int status, const char *f, ...)
73 {
74   va_list ap;
75   va_start(ap, f);
76   fprintf(stderr, "%s: ", QUIS);
77   vfprintf(stderr, f, ap);
78   va_end(ap);
79   putc('\n', stderr);
80   exit(status);
81 }
82
83 /*----- That's all, folks -------------------------------------------------*/