No empty .Rs/.Re
[netbsd-mini2440.git] / external / ibm-public / postfix / dist / src / util / msg_vstream.c
blob240c5f977e9ab00ba6cb317626128516b3e3f627
1 /* $NetBSD$ */
3 /*++
4 /* NAME
5 /* msg_vstream 3
6 /* SUMMARY
7 /* report diagnostics to VSTREAM
8 /* SYNOPSIS
9 /* #include <msg_vstream.h>
11 /* void msg_vstream_init(progname, stream)
12 /* const char *progname;
13 /* VSTREAM *stream;
14 /* DESCRIPTION
15 /* This module implements support to report msg(3) diagnostics
16 /* to a VSTREAM.
18 /* msg_vstream_init() sets the program name that appears in each output
19 /* record, and directs diagnostics (see msg(3)) to the specified
20 /* VSTREAM. The \fIprogname\fR argument is not copied.
21 /* SEE ALSO
22 /* msg(3)
23 /* BUGS
24 /* No guarantee that long records are written atomically.
25 /* Only the last msg_vstream_init() call takes effect.
26 /* LICENSE
27 /* .ad
28 /* .fi
29 /* The Secure Mailer license must be distributed with this software.
30 /* AUTHOR(S)
31 /* Wietse Venema
32 /* IBM T.J. Watson Research
33 /* P.O. Box 704
34 /* Yorktown Heights, NY 10598, USA
35 /*--*/
37 /* System libraries. */
39 #include <sys_defs.h>
40 #include <errno.h>
41 #include <stdlib.h> /* 44BSD stdarg.h uses abort() */
42 #include <stdarg.h>
44 /* Utility library. */
46 #include "vstream.h"
47 #include "msg.h"
48 #include "msg_output.h"
49 #include "msg_vstream.h"
52 * Private state.
54 static const char *msg_tag;
55 static VSTREAM *msg_stream;
57 /* msg_vstream_print - log diagnostic to VSTREAM */
59 static void msg_vstream_print(int level, const char *text)
61 static const char *level_text[] = {
62 "info", "warning", "error", "fatal", "panic",
65 if (level < 0 || level >= (int) (sizeof(level_text) / sizeof(level_text[0])))
66 msg_panic("invalid severity level: %d", level);
67 if (level == MSG_INFO) {
68 vstream_fprintf(msg_stream, "%s: %s\n",
69 msg_tag, text);
70 } else {
71 vstream_fprintf(msg_stream, "%s: %s: %s\n",
72 msg_tag, level_text[level], text);
74 vstream_fflush(msg_stream);
77 /* msg_vstream_init - initialize */
79 void msg_vstream_init(const char *name, VSTREAM *vp)
81 static int first_call = 1;
83 msg_tag = name;
84 msg_stream = vp;
85 if (first_call) {
86 first_call = 0;
87 msg_output(msg_vstream_print);