Add GNU LGPL headers to all .c .C and .h files
[oweals/cde.git] / cde / lib / tt / lib / api / c / api_xdr.C
1 /*
2  * CDE - Common Desktop Environment
3  *
4  * Copyright (c) 1993-2012, The Open Group. All rights reserved.
5  *
6  * These libraries and programs are free software; you can
7  * redistribute them and/or modify them under the terms of the GNU
8  * Lesser General Public License as published by the Free Software
9  * Foundation; either version 2 of the License, or (at your option)
10  * any later version.
11  *
12  * These libraries and programs are distributed in the hope that
13  * they will be useful, but WITHOUT ANY WARRANTY; without even the
14  * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15  * PURPOSE. See the GNU Lesser General Public License for more
16  * details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with these librararies and programs; if not, write
20  * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21  * Floor, Boston, MA 02110-1301 USA
22  */
23 //%%  (c) Copyright 1993, 1994 Hewlett-Packard Company                  
24 //%%  (c) Copyright 1993, 1994 International Business Machines Corp.    
25 //%%  (c) Copyright 1993, 1994 Sun Microsystems, Inc.                   
26 //%%  (c) Copyright 1993, 1994 Novell, Inc.                             
27 //%%  $XConsortium: api_xdr.C /main/3 1995/10/23 09:55:50 rswiston $                                                    
28 /*
29  *
30  * api_xdr.cc
31  *
32  * XDR routines for datatypes visible at the API level.
33  *
34  * Copyright (c) 1990 by Sun Microsystems, Inc.
35  */
36
37 #include "tt_options.h"
38 #if defined(OPT_BUG_SUNOS_4) && defined(__GNUG__)
39 #       include <stdlib.h>
40 #endif
41 #include <rpc/rpc.h>
42 #include "api/c/api_xdr.h"
43 #include <mp/mp_xdr_functions.h>
44 #include <malloc.h>
45
46 bool_t
47 _tt_xdr_cstring_list(XDR *xdrs, char ***ar)
48 {
49         int count;
50         char **tar;
51         int i;
52
53         if (xdrs->x_op == XDR_ENCODE) {
54                 // count the number of entries in the list
55                 tar = *ar;
56                 while (*tar++);
57                 count = tar-*ar;
58         }
59         if (!xdr_int(xdrs, &count)) return 0;
60         if (xdrs->x_op == XDR_DECODE) {
61                 // allocate a new list
62                 tar = (char **)malloc((count+1)*sizeof(char *));
63                 if (tar==(char **)0) return 0;
64                 tar[count] = (char *)0;
65                 *ar = tar;
66         } else {
67                 tar = *ar;
68         }
69         for (i=0;i<count;++i) {
70                 if (!tt_xdr_bstring(xdrs, &tar[i])) return 0;
71         }
72         if (xdrs->x_op == XDR_FREE) {
73                 free((MALLOCTYPE *)tar);
74         }
75         return 1;
76 }