Merge from vendor branch NCURSES:
[dragonfly.git] / crypto / heimdal-0.6.3 / appl / popper / pop_msg.c
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  */
6
7 #include <popper.h>
8 RCSID("$Id: pop_msg.c,v 1.16 1999/09/16 20:38:50 assar Exp $");
9
10 /* 
11  *  msg:    Send a formatted line to the POP client
12  */
13
14 int
15 pop_msg(POP *p, int stat, char *format, ...)
16 {
17     char               *mp;
18     char                message[MAXLINELEN];
19     va_list             ap;
20
21     va_start(ap, format);
22     
23     /*  Point to the message buffer */
24     mp = message;
25
26     /*  Format the POP status code at the beginning of the message */
27     snprintf (mp, sizeof(message), "%s ",
28               (stat == POP_SUCCESS) ? POP_OK : POP_ERR);
29
30     /*  Point past the POP status indicator in the message message */
31     mp += strlen(mp);
32
33     /*  Append the message (formatted, if necessary) */
34     if (format) 
35         vsnprintf (mp, sizeof(message) - strlen(message),
36                    format, ap);
37     
38     /*  Log the message if debugging is turned on */
39 #ifdef DEBUG
40     if (p->debug && stat == POP_SUCCESS)
41         pop_log(p,POP_DEBUG,"%s",message);
42 #endif /* DEBUG */
43
44     /*  Log the message if a failure occurred */
45     if (stat != POP_SUCCESS) 
46         pop_log(p,POP_PRIORITY,"%s",message);
47
48     /*  Append the <CR><LF> */
49     strlcat(message, "\r\n", sizeof(message));
50         
51     /*  Send the message to the client */
52     fputs(message, p->output);
53     fflush(p->output);
54
55     va_end(ap);
56     return(stat);
57 }