2 static char sfs_xdr_stdio_id[] = "@(#)xdr_stdio.c 2.1 97/10/23";
4 /* @(#)xdr_stdio.c 2.1 88/07/29 4.0 RPCSRC */
6 * Copyright (c) 1992-1997,2001 by Standard Performance Evaluation Corporation
8 * Standard Performance Evaluation Corporation (SPEC)
9 * 6585 Merchant Place, Suite 100
12 * This product contains benchmarks acquired from several sources who
13 * understand and agree with SPEC's goal of creating fair and objective
14 * benchmarks to measure computer performance.
16 * This copyright notice is placed here only to protect SPEC in the
17 * event the source is misused in any manner that is contrary to the
18 * spirit, the goals and the intent of SPEC.
20 * The source code is provided to the user or company under the license
21 * agreement for the SPEC Benchmark Suite for this product.
24 * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
25 * unrestricted use provided that this legend is included on all tape
26 * media and as a part of the software program in whole or part. Users
27 * may copy or modify Sun RPC without charge, but are not authorized
28 * to license or distribute it to anyone else except as part of a product or
29 * program developed by the user.
31 * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
32 * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
33 * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
35 * Sun RPC is provided with no support and without any obligation on the
36 * part of Sun Microsystems, Inc. to assist in its use, correction,
37 * modification or enhancement.
39 * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
40 * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
41 * OR ANY PART THEREOF.
43 * In no event will Sun Microsystems, Inc. be liable for any lost revenue
44 * or profits or other special, indirect and consequential damages, even if
45 * Sun has been advised of the possibility of such damages.
47 * Sun Microsystems, Inc.
49 * Mountain View, California 94043
51 #if !defined(lint) && defined(SCCSIDS)
52 static char sccsid[] = "@(#)xdr_stdio.c 1.16 87/08/11 Copyr 1984 Sun Micro";
56 * xdr_stdio.c, XDR implementation on standard i/o file.
58 * Copyright (C) 1984, Sun Microsystems, Inc.
60 * This set of routines implements a XDR on a stdio stream.
61 * XDR_ENCODE serializes onto the stream, XDR_DECODE de-serializes
66 #include <sys/types.h>
67 #include "rpc/types.h"
69 #include "rpc/osdep.h"
71 static bool_t xdrstdio_getlong(XDR *, int32_t *);
72 static bool_t xdrstdio_putlong(XDR *, int32_t *);
73 static bool_t xdrstdio_getbytes(XDR *, void *, uint_t);
74 static bool_t xdrstdio_putbytes(XDR *, void *, uint_t);
75 static uint_t xdrstdio_getpos(XDR *);
76 static bool_t xdrstdio_setpos(XDR *, uint_t);
77 static int32_t *xdrstdio_inline(XDR *, uint_t);
78 static void xdrstdio_destroy(XDR *);
81 * Ops vector for stdio type XDR
83 static struct xdr_ops xdrstdio_ops = {
84 xdrstdio_getlong, /* deseraialize a long int */
85 xdrstdio_putlong, /* seraialize a long int */
86 xdrstdio_getbytes, /* deserialize counted bytes */
87 xdrstdio_putbytes, /* serialize counted bytes */
88 xdrstdio_getpos, /* get offset in the stream */
89 xdrstdio_setpos, /* set offset in the stream */
90 xdrstdio_inline, /* prime stream for inline macros */
91 xdrstdio_destroy /* destroy stream */
95 * Initialize a stdio xdr stream.
96 * Sets the xdr stream handle xdrs for use on the stream file.
97 * Operation flag is set to op.
107 xdrs->x_ops = &xdrstdio_ops;
108 xdrs->x_private = (void *)file;
114 * Destroy a stdio xdr stream.
115 * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create.
121 (void)fflush((FILE *)xdrs->x_private);
122 /* xx should we close the file ?? */
131 if (fread((void *)lp, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
143 int32_t mycopy = htonl(*lp);
146 if (fwrite((void *)lp, sizeof(int32_t), 1, (FILE *)xdrs->x_private) != 1)
158 if ((len != 0) && (fread(addr, (int)len, 1, (FILE *)xdrs->x_private) != 1))
170 if ((len != 0) && (fwrite(addr, (int)len, 1, (FILE *)xdrs->x_private) != 1))
180 return ((uint_t) ftell((FILE *)xdrs->x_private));
189 return ((fseek((FILE *)xdrs->x_private, (int32_t)pos, 0) < 0) ?
201 * Must do some work to implement this: must insure
202 * enough data in the underlying stdio buffer,
203 * that the buffer is aligned so that we can indirect through a
204 * int32_t *, and stuff this pointer in xdrs->x_buf. Doing
205 * a fread or fwrite to a scratch buffer would defeat
206 * most of the gains to be had here and require storage
207 * management on this buffer, so we don't do this.