Main Page   Modules   Alphabetical List   Compound List   File List   Compound Members   File Members   Related Pages  

/projects/cubeos/src_current/net/rpc/xdr_stdio.c

Go to the documentation of this file.
00001 /* @(#)xdr_stdio.c      2.1 88/07/29 4.0 RPCSRC */
00002 /*
00003  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
00004  * unrestricted use provided that this legend is included on all tape
00005  * media and as a part of the software program in whole or part.  Users
00006  * may copy or modify Sun RPC without charge, but are not authorized
00007  * to license or distribute it to anyone else except as part of a product or
00008  * program developed by the user.
00009  * 
00010  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
00011  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
00012  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
00013  * 
00014  * Sun RPC is provided with no support and without any obligation on the
00015  * part of Sun Microsystems, Inc. to assist in its use, correction,
00016  * modification or enhancement.
00017  * 
00018  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
00019  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
00020  * OR ANY PART THEREOF.
00021  * 
00022  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
00023  * or profits or other special, indirect and consequential damages, even if
00024  * Sun has been advised of the possibility of such damages.
00025  * 
00026  * Sun Microsystems, Inc.
00027  * 2550 Garcia Avenue
00028  * Mountain View, California  94043
00029  */
00030 #if !defined(lint) && defined(SCCSIDS)
00031 static char sccsid[] = "@(#)xdr_stdio.c 1.16 87/08/11 Copyr 1984 Sun Micro";
00032 #endif
00033 
00034 /*
00035  * xdr_stdio.c, XDR implementation on standard i/o file.
00036  *
00037  * Copyright (C) 1984, Sun Microsystems, Inc.
00038  *
00039  * This set of routines implements a XDR on a stdio stream.
00040  * XDR_ENCODE serializes onto the stream, XDR_DECODE de-serializes
00041  * from the stream.
00042  */
00043 
00048 #include <rpc/types.h>
00049 #include <stdio.h>
00050 #include <rpc/xdr.h>
00051 
00052 static bool_t xdrstdio_getlong ();
00053 static bool_t xdrstdio_putlong ();
00054 static bool_t xdrstdio_getbytes ();
00055 static bool_t xdrstdio_putbytes ();
00056 static u_int xdrstdio_getpos ();
00057 static bool_t xdrstdio_setpos ();
00058 static long *xdrstdio_inline ();
00059 static void xdrstdio_destroy ();
00060 
00061 /*
00062  * Ops vector for stdio type XDR
00063  */
00064 static struct xdr_ops xdrstdio_ops =
00065 {
00066         xdrstdio_getlong,       /* deseraialize a long int */
00067         xdrstdio_putlong,       /* seraialize a long int */
00068         xdrstdio_getbytes,      /* deserialize counted bytes */
00069         xdrstdio_putbytes,      /* serialize counted bytes */
00070         xdrstdio_getpos,        /* get offset in the stream */
00071         xdrstdio_setpos,        /* set offset in the stream */
00072         xdrstdio_inline,        /* prime stream for inline macros */
00073         xdrstdio_destroy        /* destroy stream */
00074 };
00075 
00076 /*
00077  * Initialize a stdio xdr stream.
00078  * Sets the xdr stream handle xdrs for use on the stream file.
00079  * Operation flag is set to op.
00080  */
00081 void xdrstdio_create (xdrs, file, op)
00082      register XDR *xdrs;
00083      FILE *file;
00084      enum xdr_op op;
00085 {
00086 
00087         xdrs->x_op = op;
00088         xdrs->x_ops = &xdrstdio_ops;
00089         xdrs->x_private = (caddr_t) file;
00090         xdrs->x_handy = 0;
00091         xdrs->x_base = 0;
00092 }
00093 
00094 /*
00095  * Destroy a stdio xdr stream.
00096  * Cleans up the xdr stream handle xdrs previously set up by xdrstdio_create.
00097  */
00098 static void xdrstdio_destroy (xdrs)
00099      register XDR *xdrs;
00100 {
00101         (void) fflush ((FILE *) xdrs->x_private);
00102         /* xx should we close the file ?? */
00103 };
00104 
00105 static bool_t
00106   xdrstdio_getlong (xdrs, lp)
00107      XDR *xdrs;
00108      register long *lp;
00109 {
00110 
00111         if (fread ((caddr_t) lp, sizeof (long), 1, (FILE *) xdrs->x_private) != 1)
00112                   return (FALSE);
00113 #ifndef mc68000
00114         *lp = ntohl (*lp);
00115 #endif
00116         return (TRUE);
00117 }
00118 
00119 static bool_t
00120   xdrstdio_putlong (xdrs, lp)
00121      XDR *xdrs;
00122      long *lp;
00123 {
00124 
00125 #ifndef mc68000
00126         long mycopy = htonl (*lp);
00127         lp = &mycopy;
00128 #endif
00129         if (fwrite ((caddr_t) lp, sizeof (long), 1, (FILE *) xdrs->x_private) != 1)
00130                   return (FALSE);
00131         return (TRUE);
00132 }
00133 
00134 static bool_t
00135   xdrstdio_getbytes (xdrs, addr, len)
00136      XDR *xdrs;
00137      caddr_t addr;
00138      u_int len;
00139 {
00140 
00141         if ((len != 0) && (fread (addr, (int) len, 1, (FILE *) xdrs->x_private) != 1))
00142                 return (FALSE);
00143         return (TRUE);
00144 }
00145 
00146 static bool_t
00147   xdrstdio_putbytes (xdrs, addr, len)
00148      XDR *xdrs;
00149      caddr_t addr;
00150      u_int len;
00151 {
00152 
00153         if ((len != 0) && (fwrite (addr, (int) len, 1, (FILE *) xdrs->x_private) != 1))
00154                 return (FALSE);
00155         return (TRUE);
00156 }
00157 
00158 static u_int
00159   xdrstdio_getpos (xdrs)
00160      XDR *xdrs;
00161 {
00162 
00163         return ((u_int) ftell ((FILE *) xdrs->x_private));
00164 }
00165 
00166 static bool_t
00167   xdrstdio_setpos (xdrs, pos)
00168      XDR *xdrs;
00169      u_int pos;
00170 {
00171 
00172         return ((fseek ((FILE *) xdrs->x_private, (long) pos, 0) < 0) ?
00173                 FALSE : TRUE);
00174 }
00175 
00176 static long *
00177   xdrstdio_inline (xdrs, len)
00178      XDR *xdrs;
00179      u_int len;
00180 {
00181 
00182         /*
00183          * Must do some work to implement this: must insure
00184          * enough data in the underlying stdio buffer,
00185          * that the buffer is aligned so that we can indirect through a
00186          * long *, and stuff this pointer in xdrs->x_buf.  Doing
00187          * a fread or fwrite to a scratch buffer would defeat
00188          * most of the gains to be had here and require storage
00189          * management on this buffer, so we don't do this.
00190          */
00191         return (NULL);
00192 }

Generated on Thu Feb 20 15:38:46 2003 for cubeOS by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002