00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
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 
00036 
00037 
00038 
00039 
00040 
00041 
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 
00063 
00064 static struct xdr_ops xdrstdio_ops =
00065 {
00066         xdrstdio_getlong,       
00067         xdrstdio_putlong,       
00068         xdrstdio_getbytes,      
00069         xdrstdio_putbytes,      
00070         xdrstdio_getpos,        
00071         xdrstdio_setpos,        
00072         xdrstdio_inline,        
00073         xdrstdio_destroy        
00074 };
00075 
00076 
00077 
00078 
00079 
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 
00096 
00097 
00098 static void xdrstdio_destroy (xdrs)
00099      register XDR *xdrs;
00100 {
00101         (void) fflush ((FILE *) xdrs->x_private);
00102         
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 
00184 
00185 
00186 
00187 
00188 
00189 
00190 
00191         return (NULL);
00192 }