]> git.ipfire.org Git - thirdparty/glibc.git/blame - sunrpc/xdr_ref.c
Convert 703 function definitions to prototype style.
[thirdparty/glibc.git] / sunrpc / xdr_ref.c
CommitLineData
28f540f4 1/*
a7ab6ec8 2 * xdr_reference.c, Generic XDR routines implementation.
6d52618b 3 *
a7ab6ec8 4 * Copyright (c) 2010, Oracle America, Inc.
6d52618b 5 *
a7ab6ec8
UD
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions are
8 * met:
6d52618b 9 *
a7ab6ec8
UD
10 * * Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * * Redistributions in binary form must reproduce the above
13 * copyright notice, this list of conditions and the following
14 * disclaimer in the documentation and/or other materials
15 * provided with the distribution.
16 * * Neither the name of the "Oracle America, Inc." nor the names of its
17 * contributors may be used to endorse or promote products derived
18 * from this software without specific prior written permission.
cb636bb2 19 *
a7ab6ec8
UD
20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
23 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
24 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
25 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
27 * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28f540f4 32 *
a7ab6ec8
UD
33 * These are the "non-trivial" xdr primitives used to serialize and
34 * de-serialize "pointers". See xdr.h for more info on the interface to xdr.
28f540f4
RM
35 */
36
37#include <stdio.h>
e7fd8a39 38#include <string.h>
28f540f4
RM
39#include <rpc/types.h>
40#include <rpc/xdr.h>
4360eafd 41#include <libintl.h>
3ce1f295
UD
42#include <wchar.h>
43#include <libio/iolibio.h>
50304ef0 44
28f540f4
RM
45#define LASTUNSIGNED ((u_int)0-1)
46
47/*
48 * XDR an indirect pointer
49 * xdr_reference is for recursively translating a structure that is
50 * referenced by a pointer inside the structure that is currently being
51 * translated. pp references a pointer to storage. If *pp is null
52 * the necessary storage is allocated.
6d52618b 53 * size is the size of the referneced structure.
28f540f4
RM
54 * proc is the routine to handle the referenced structure.
55 */
56bool_t
e7fd8a39
UD
57xdr_reference (xdrs, pp, size, proc)
58 XDR *xdrs;
59 caddr_t *pp; /* the pointer to work on */
60 u_int size; /* size of the object pointed to */
61 xdrproc_t proc; /* xdr routine to handle the object */
28f540f4 62{
e7fd8a39
UD
63 caddr_t loc = *pp;
64 bool_t stat;
28f540f4 65
e7fd8a39
UD
66 if (loc == NULL)
67 switch (xdrs->x_op)
68 {
69 case XDR_FREE:
70 return TRUE;
28f540f4 71
e7fd8a39 72 case XDR_DECODE:
cdb9c321 73 *pp = loc = (caddr_t) calloc (1, size);
e7fd8a39
UD
74 if (loc == NULL)
75 {
1d20f7f8 76 (void) __fxprintf (NULL, "%s: %s", __func__, _("out of memory\n"));
e7fd8a39
UD
77 return FALSE;
78 }
e7fd8a39
UD
79 break;
80 default:
81 break;
82 }
28f540f4 83
e7fd8a39 84 stat = (*proc) (xdrs, loc, LASTUNSIGNED);
28f540f4 85
e7fd8a39
UD
86 if (xdrs->x_op == XDR_FREE)
87 {
88 mem_free (loc, size);
89 *pp = NULL;
90 }
91 return stat;
28f540f4 92}
021db4be 93libc_hidden_nolink_sunrpc (xdr_reference, GLIBC_2_0)
28f540f4
RM
94
95
96/*
97 * xdr_pointer():
98 *
99 * XDR a pointer to a possibly recursive data structure. This
6d52618b 100 * differs with xdr_reference in that it can serialize/deserialize
28f540f4
RM
101 * trees correctly.
102 *
103 * What's sent is actually a union:
104 *
105 * union object_pointer switch (boolean b) {
106 * case TRUE: object_data data;
107 * case FALSE: void nothing;
108 * }
109 *
110 * > objpp: Pointer to the pointer to the object.
111 * > obj_size: size of the object.
112 * > xdr_obj: routine to XDR an object.
113 *
114 */
115bool_t
9d46370c 116xdr_pointer (XDR *xdrs, char **objpp, u_int obj_size, xdrproc_t xdr_obj)
28f540f4
RM
117{
118
e7fd8a39 119 bool_t more_data;
28f540f4 120
e7fd8a39 121 more_data = (*objpp != NULL);
7b57bfe5 122 if (!xdr_bool (xdrs, &more_data))
e7fd8a39
UD
123 {
124 return FALSE;
125 }
126 if (!more_data)
127 {
128 *objpp = NULL;
129 return TRUE;
130 }
7b57bfe5 131 return xdr_reference (xdrs, objpp, obj_size, xdr_obj);
28f540f4 132}
7b57bfe5
UD
133#ifdef EXPORT_RPC_SYMBOLS
134libc_hidden_def (xdr_pointer)
135#else
021db4be 136libc_hidden_nolink_sunrpc (xdr_pointer, GLIBC_2_0)
7b57bfe5 137#endif