]> asedeno.scripts.mit.edu Git - 1ts-debian.git/blob - zephyr/lib/ZFmtRawLst.c
r4254@bucket (orig r244): kcr | 2008-01-20 14:40:42 -0500
[1ts-debian.git] / zephyr / lib / ZFmtRawLst.c
1 /* This file is part of the Project Athena Zephyr Notification System.
2  * It contains source for the ZFormatRawNoticeList function.
3  *
4  *      Created by:     Robert French
5  *
6  *      $Id$
7  *
8  *      Copyright (c) 1987 by the Massachusetts Institute of Technology.
9  *      For copying and distribution information, see the file
10  *      "mit-copyright.h". 
11  */
12
13 #ifndef lint
14 static char rcsid_ZFormatRawNoticeList_c[] = "$Id$";
15 #endif
16
17 #include <internal.h>
18
19 Code_t
20 ZFormatRawNoticeList(ZNotice_t *notice,
21                      char *list[],
22                      int nitems,
23                      char **buffer,
24                      int *ret_len)
25 {
26     char header[Z_MAXHEADERLEN];
27     int hdrlen, i, size;
28     char *ptr;
29     Code_t retval;
30
31     if ((retval = Z_FormatRawHeader(notice, header, sizeof(header),
32                                     &hdrlen, NULL, NULL)) != ZERR_NONE)
33         return (retval);
34
35     size = 0;
36     for (i=0;i<nitems;i++)
37         size += strlen(list[i])+1;
38
39     *ret_len = hdrlen+size;
40     
41     if (!(*buffer = (char *) malloc((unsigned) *ret_len)))
42         return (ENOMEM);
43
44     (void) memcpy(*buffer, header, hdrlen);
45     
46     ptr = *buffer+hdrlen;
47
48     for (;nitems;nitems--, list++) {
49         i = strlen(*list)+1;
50         (void) memcpy(ptr, *list, i);
51         ptr += i;
52     }
53
54     return (ZERR_NONE);
55 }