ReactOS 0.4.16-dev-112-g52265ae
xdr_sizeof.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009, Sun Microsystems, Inc.
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * - Redistributions of source code must retain the above copyright notice,
8 * this list of conditions and the following disclaimer.
9 * - Redistributions in binary form must reproduce the above copyright notice,
10 * this list of conditions and the following disclaimer in the documentation
11 * and/or other materials provided with the distribution.
12 * - Neither the name of Sun Microsystems, Inc. nor the names of its
13 * contributors may be used to endorse or promote products derived
14 * from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28/*
29 * xdr_sizeof.c
30 *
31 * Copyright 1990 Sun Microsystems, Inc.
32 *
33 * General purpose routine to see how much space something will use
34 * when serialized using XDR.
35 */
36
37//#include <sys/cdefs.h>
38
39#include <wintirpc.h>
40#include "namespace.h"
41#include <rpc/types.h>
42#include <rpc/xdr.h>
43#include <sys/types.h>
44#include <stdlib.h>
45#include "un-namespace.h"
46
47/* ARGSUSED */
48static bool_t
49x_putlong(XDR *xdrs, const long *longp)
50{
52 return (TRUE);
53}
54
55/* ARGSUSED */
56static bool_t
57x_putbytes(XDR *xdrs, const char *bp, u_int len)
58{
59 xdrs->x_handy += len;
60 return (TRUE);
61}
62
63static u_int
65{
66 return (xdrs->x_handy);
67}
68
69/* ARGSUSED */
70static bool_t
72{
73 /* This is not allowed */
74 return (FALSE);
75}
76
77static int32_t *
79{
80 if (len == 0) {
81 return (NULL);
82 }
83 if (xdrs->x_op != XDR_ENCODE) {
84 return (NULL);
85 }
86 if (len < PtrToUlong(xdrs->x_base)) {
87 /* x_private was already allocated */
88 xdrs->x_handy += len;
89 return ((int32_t *) xdrs->x_private);
90 } else {
91 /* Free the earlier space and allocate new area */
92 if (xdrs->x_private)
93 free(xdrs->x_private);
94 if ((xdrs->x_private = (caddr_t) malloc(len)) == NULL) {
95 xdrs->x_base = 0;
96 return (NULL);
97 }
98 xdrs->x_base = UIntToPtr(len);
99 //xdrs->x_base = len; // XXX Is this right???
100 xdrs->x_handy += len;
101 return ((int32_t *) xdrs->x_private);
102 }
103}
104
105static int
107{
108 /* Always return FALSE/NULL, as the case may be */
109 return (0);
110}
111
112static void
114{
115 xdrs->x_handy = 0;
116 xdrs->x_base = 0;
117 if (xdrs->x_private) {
118 free(xdrs->x_private);
119 xdrs->x_private = NULL;
120 }
121 return;
122}
123
124unsigned long
127 void *data;
128{
129 XDR x;
130 struct xdr_ops ops;
131 bool_t stat;
132 /* to stop ANSI-C compiler from complaining */
133 typedef bool_t (* dummyfunc1)(XDR *, long *);
134 typedef bool_t (* dummyfunc2)(XDR *, caddr_t, u_int);
135
136 ops.x_putlong = x_putlong;
137 ops.x_putbytes = x_putbytes;
138 ops.x_inline = x_inline;
139 ops.x_getpostn = x_getpostn;
140 ops.x_setpostn = x_setpostn;
141 ops.x_destroy = x_destroy;
142
143 /* the other harmless ones */
144 ops.x_getlong = (dummyfunc1) harmless;
145 ops.x_getbytes = (dummyfunc2) harmless;
146
147 x.x_op = XDR_ENCODE;
148 x.x_ops = &ops;
149 x.x_handy = 0;
150 x.x_private = (caddr_t) NULL;
151 x.x_base = (caddr_t) 0;
152
153 stat = func(&x, data);
154 if (x.x_private)
155 free(x.x_private);
156 return (stat == TRUE ? (unsigned) x.x_handy: 0);
157}
#define stat
Definition: acwin.h:99
#define caddr_t
Definition: ftp.c:24
#define UIntToPtr(ui)
Definition: basetsd.h:90
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
UINT32 u_int
Definition: types.h:82
#define NULL
Definition: types.h:112
int32_t bool_t
Definition: types.h:101
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
INT32 int32_t
Definition: types.h:71
#define PtrToUlong(u)
Definition: config.h:107
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLenum func
Definition: glext.h:6028
GLenum GLsizei len
Definition: glext.h:6722
char * caddr_t
Definition: rosdhcp.h:36
Definition: xdr.h:103
enum xdr_op x_op
Definition: xdr.h:104
char * x_base
Definition: xdr.h:126
void * x_private
Definition: xdr.h:125
u_int x_handy
Definition: xdr.h:127
Definition: stat.h:55
@ XDR_ENCODE
Definition: xdr.h:85
bool_t(* xdrproc_t)(XDR *,...)
Definition: xdr.h:144
#define BYTES_PER_XDR_UNIT
Definition: xdr.h:93
static bool_t x_putlong(XDR *xdrs, const long *longp)
Definition: xdr_sizeof.c:49
static bool_t x_setpostn(XDR *xdrs, u_int pos)
Definition: xdr_sizeof.c:71
static bool_t x_putbytes(XDR *xdrs, const char *bp, u_int len)
Definition: xdr_sizeof.c:57
static int32_t * x_inline(XDR *xdrs, u_int len)
Definition: xdr_sizeof.c:78
static int harmless()
Definition: xdr_sizeof.c:106
unsigned long xdr_sizeof(xdrproc_t func, void *data)
Definition: xdr_sizeof.c:125
static void x_destroy(XDR *xdrs)
Definition: xdr_sizeof.c:113
static u_int x_getpostn(XDR *xdrs)
Definition: xdr_sizeof.c:64