]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZFmtList.c
finalize -3
[1ts-debian.git] / zephyr / lib / ZFmtList.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains source for the ZFormatNoticeList function.
3  *
4  *      Created by:     Robert French
5  *
6  *      $Id$
7  *
8  *      Copyright (c) 1987,1991 by the Massachusetts Institute of Technology.
9  *      For copying and distribution information, see the file
10  *      "mit-copyright.h". 
11  */
12
13 #include <internal.h>
14
15 #ifndef lint
16 static const char rcsid_ZFormatNoticeList_c[] =
17     "$Id$";
18 #endif
19
20 Code_t ZFormatNoticeList(notice, list, nitems, buffer, ret_len, 
21                          cert_routine)
22     ZNotice_t *notice;
23     register char **list;
24     int nitems;
25     char **buffer;
26     int *ret_len;
27     Z_AuthProc cert_routine;
28 {
29     char header[Z_MAXHEADERLEN];
30     register int i;
31     int hdrlen, size;
32     char *ptr;
33     Code_t retval;
34
35     if ((retval = Z_FormatHeader(notice, header, sizeof(header), &hdrlen,
36                                  cert_routine)) != ZERR_NONE)
37         return (retval);
38
39     size = 0;
40     for (i=0;i<nitems;i++)
41         size += strlen(list[i])+1;
42
43     *ret_len = hdrlen+size;
44
45     /* *ret_len can never be zero here, no need to worry about malloc(0). */
46     if (!(*buffer = (char *) malloc((unsigned)*ret_len)))
47         return (ENOMEM);
48
49     (void) memcpy(*buffer, header, hdrlen);
50
51     ptr = *buffer+hdrlen;
52
53     for (;nitems;nitems--, list++) {
54         i = strlen(*list)+1;
55         (void) memcpy(ptr, *list, i);
56         ptr += i;
57     }
58
59     return (ZERR_NONE);
60 }