Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

xdr_stdi.c

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

Generated on Sun Dec 2 15:56:54 2001 for rcslib by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001