]> diplodocus.org Git - nmh/blob - docs/historical/mh-6.8.5/sbr/advertise.c
Always check that mktemp()/mktemp2() succeeds before trying to
[nmh] / docs / historical / mh-6.8.5 / sbr / advertise.c
1 /* advertise.c - the heart of adios */
2 #ifndef lint
3 static char ident[] = "@(#)$Id: advertise.c,v 1.4 1993/08/25 17:18:31 jromine Exp shettich $";
4 #endif /* lint */
5
6 #include "../h/mh.h"
7 #include <stdio.h>
8 #ifdef BSD42
9 #include <sys/types.h>
10 #include <sys/uio.h>
11 #endif /* BSD42 */
12 #include <errno.h>
13 /* For 4.2BSD systems, use writev() for slightly better performance. Why?
14 Well, there are a couple of reasons. Primarily, it gives a smoother
15 output... More importantly though, it's a sexy syscall()...
16 */
17
18 extern int errno;
19 #ifndef BSD44 /* in <stdio.h> */
20 extern int sys_nerr;
21 extern const char *sys_errlist[];
22 #endif
23
24 /* \f */
25
26 /* VARARGS3 */
27
28 void advertise (what, tail, fmt, a, b, c, d, e, f)
29 char *what,
30 *tail,
31 *fmt,
32 *a,
33 *b,
34 *c,
35 *d,
36 *e,
37 *f;
38 {
39 int eindex = errno;
40 #ifdef BSD42
41 char buffer[BUFSIZ],
42 err[BUFSIZ];
43 struct iovec iob[20];
44 register struct iovec *iov = iob;
45 #endif /* BSD42 */
46
47 (void) fflush (stdout);
48
49 #ifndef BSD42
50 if (invo_name && *invo_name)
51 fprintf (stderr, "%s: ", invo_name);
52 fprintf (stderr, fmt, a, b, c, d, e, f);
53 if (what) {
54 if (*what)
55 fprintf (stderr, " %s: ", what);
56 if (eindex > 0 && eindex < sys_nerr)
57 fprintf (stderr, "%s", sys_errlist[eindex]);
58 else
59 fprintf (stderr, "Error %d", eindex);
60 }
61 if (tail)
62 fprintf (stderr, ", %s", tail);
63 (void) fputc ('\n', stderr);
64 #else /* BSD42 */
65 (void) fflush (stderr);
66
67 if (invo_name && *invo_name) {
68 iov -> iov_len = strlen (iov -> iov_base = invo_name);
69 iov++;
70 iov -> iov_len = strlen (iov -> iov_base = ": ");
71 iov++;
72 }
73
74 (void) sprintf (buffer, fmt, a, b, c, d, e, f);
75 iov -> iov_len = strlen (iov -> iov_base = buffer);
76 iov++;
77 if (what) {
78 if (*what) {
79 iov -> iov_len = strlen (iov -> iov_base = " ");
80 iov++;
81 iov -> iov_len = strlen (iov -> iov_base = what);
82 iov++;
83 iov -> iov_len = strlen (iov -> iov_base = ": ");
84 iov++;
85 }
86 if (eindex > 0 && eindex < sys_nerr)
87 iov -> iov_len = strlen (iov -> iov_base = sys_errlist[eindex]);
88 else {
89 (void) sprintf (err, "Error %d", eindex);
90 iov -> iov_len = strlen (iov -> iov_base = err);
91 }
92 iov++;
93 }
94 if (tail && *tail) {
95 iov -> iov_len = strlen (iov -> iov_base = ", ");
96 iov++;
97 iov -> iov_len = strlen (iov -> iov_base = tail);
98 iov++;
99 }
100 iov -> iov_len = strlen (iov -> iov_base = "\n");
101 iov++;
102 (void) writev (fileno (stderr), iob, iov - iob);
103 #endif /* BSD42 */
104 }