]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZFmtList.c
first pass de-K&Rify lib
[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
21 ZFormatNoticeList(ZNotice_t *notice,
22                   register char **list,
23                   int nitems,
24                   char **buffer,
25                   int *ret_len, 
26                   Z_AuthProc cert_routine)
27 {
28     char header[Z_MAXHEADERLEN];
29     register int i;
30     int hdrlen, size;
31     char *ptr;
32     Code_t retval;
33
34     if ((retval = Z_FormatHeader(notice, header, sizeof(header), &hdrlen,
35                                  cert_routine)) != ZERR_NONE)
36         return (retval);
37
38     size = 0;
39     for (i=0;i<nitems;i++)
40         size += strlen(list[i])+1;
41
42     *ret_len = hdrlen+size;
43
44     /* *ret_len can never be zero here, no need to worry about malloc(0). */
45     if (!(*buffer = (char *) malloc((unsigned)*ret_len)))
46         return (ENOMEM);
47
48     (void) memcpy(*buffer, header, hdrlen);
49
50     ptr = *buffer+hdrlen;
51
52     for (;nitems;nitems--, list++) {
53         i = strlen(*list)+1;
54         (void) memcpy(ptr, *list, i);
55         ptr += i;
56     }
57
58     return (ZERR_NONE);
59 }