No empty .Rs/.Re
[netbsd-mini2440.git] / crypto / dist / heimdal / appl / popper / pop_msg.c
blobc91bcf07370e14886bd0167691b074fc7579233e
1 /*
2 * Copyright (c) 1989 Regents of the University of California.
3 * All rights reserved. The Berkeley software License Agreement
4 * specifies the terms and conditions for redistribution.
5 */
7 #include <popper.h>
8 __RCSID("$Heimdal: pop_msg.c 6984 1999-09-16 20:41:57Z assar $"
9 "$NetBSD$");
11 /*
12 * msg: Send a formatted line to the POP client
15 int
16 pop_msg(POP *p, int stat, char *format, ...)
18 char *mp;
19 char message[MAXLINELEN];
20 va_list ap;
22 va_start(ap, format);
24 /* Point to the message buffer */
25 mp = message;
27 /* Format the POP status code at the beginning of the message */
28 snprintf (mp, sizeof(message), "%s ",
29 (stat == POP_SUCCESS) ? POP_OK : POP_ERR);
31 /* Point past the POP status indicator in the message message */
32 mp += strlen(mp);
34 /* Append the message (formatted, if necessary) */
35 if (format)
36 vsnprintf (mp, sizeof(message) - strlen(message),
37 format, ap);
39 /* Log the message if debugging is turned on */
40 #ifdef DEBUG
41 if (p->debug && stat == POP_SUCCESS)
42 pop_log(p,POP_DEBUG,"%s",message);
43 #endif /* DEBUG */
45 /* Log the message if a failure occurred */
46 if (stat != POP_SUCCESS)
47 pop_log(p,POP_PRIORITY,"%s",message);
49 /* Append the <CR><LF> */
50 strlcat(message, "\r\n", sizeof(message));
52 /* Send the message to the client */
53 fputs(message, p->output);
54 fflush(p->output);
56 va_end(ap);
57 return(stat);