irix label changes rx subdir
[openafs.git] / src / rx / xdr_len.c
1 /*
2  * Copyright (c) 2010 Your Filesystem Inc. All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR `AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24
25 #include <afsconfig.h>
26 #include <afs/param.h>
27
28 #include <stdlib.h>
29 #include "xdr.h"
30
31 static void
32 xdrlen_destroy(AFS_XDRS_T axdrs)
33 {
34 }
35
36 static bool_t
37 xdrlen_getint32(AFS_XDRS_T axdrs, afs_int32 * lp)
38 {
39     return (FALSE);
40 }
41
42 static bool_t
43 xdrlen_putint32(AFS_XDRS_T axdrs, afs_int32 * lp)
44 {
45     XDR * xdrs = (XDR *)axdrs;
46
47     xdrs->x_handy += sizeof(afs_int32);
48     return (TRUE);
49 }
50
51 static bool_t
52 xdrlen_getbytes(AFS_XDRS_T axdrs, caddr_t addr, u_int len)
53 {
54     return (FALSE);
55 }
56
57 static bool_t
58 xdrlen_putbytes(AFS_XDRS_T axdrs, caddr_t addr, u_int len)
59 {
60     XDR * xdrs = (XDR *)axdrs;
61
62     xdrs->x_handy += len;
63     return (TRUE);
64 }
65
66 static u_int
67 xdrlen_getpos(AFS_XDRS_T axdrs)
68 {
69     XDR * xdrs = (XDR *)axdrs;
70
71     return xdrs->x_handy;
72 }
73
74 static bool_t
75 xdrlen_setpos(AFS_XDRS_T axdrs, u_int pos)
76 {
77     XDR * xdrs = (XDR *)axdrs;
78
79     xdrs->x_handy = pos;
80     return (TRUE);
81 }
82
83 static afs_int32 *
84 xdrlen_inline(AFS_XDRS_T axdrs, u_int len)
85 {
86     return NULL;
87 }
88
89 static struct xdr_ops xdrlen_ops = {
90 #if defined(AFS_NT40_ENV) || (defined(AFS_SGI_ENV) && !defined(__c99))
91     /* Windows does not support labeled assigments */
92     xdrlen_getint32,    /* not supported */
93     xdrlen_putint32,    /* serialize an afs_int32 */
94     xdrlen_getbytes,    /* not supported */
95     xdrlen_putbytes,    /* serialize counted bytes */
96     xdrlen_getpos,      /* get offset in the stream */
97     xdrlen_setpos,      /* set offset in the stream */
98     xdrlen_inline,      /* not supported */
99     xdrlen_destroy      /* destroy stream */
100 #else
101     .x_getint32 = xdrlen_getint32,
102     .x_putint32 = xdrlen_putint32,
103     .x_getbytes = xdrlen_getbytes,
104     .x_putbytes = xdrlen_putbytes,
105     .x_getpostn = xdrlen_getpos,
106     .x_setpostn = xdrlen_setpos,
107     .x_inline = xdrlen_inline,
108     .x_destroy = xdrlen_destroy
109 #endif
110 };
111
112 /**
113  * Initialise an XDR stream to calculate the space required to encode
114  *
115  * This initialises an XDR stream object which can be used to calculate
116  * the space required to encode a particular structure into memory. No
117  * encoding is actually performed, a later call using xdrmem is necessary
118  * to do so.
119  *
120  * @param xdrs
121  *      A pointer to a preallocated XDR sized block of memory.
122  */
123 void
124 xdrlen_create(XDR * xdrs)
125 {
126     xdrs->x_op = XDR_ENCODE;
127     xdrs->x_ops = &xdrlen_ops;
128     xdrs->x_handy = 0;
129 }