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
00031
00032
00033
00034
00035
00036
00037
00038
00039
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
00047
00048
00049
00050
00051
00052
00053
00054
00055 #include <stdio.h>
00056 #include <stdlib.h>
00057
00058 #ifdef UNDER_CE
00059 #include <windows.h>
00060 #include <winsock.h>
00061 #else
00062 #include <winsock2.h>
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
00078
00079 static struct xdr_ops xdrstdio_ops = {
00080 xdrstdio_getlong,
00081 xdrstdio_putlong,
00082 xdrstdio_getbytes,
00083 xdrstdio_putbytes,
00084 xdrstdio_getpos,
00085 xdrstdio_setpos,
00086 xdrstdio_inline,
00087 xdrstdio_destroy
00088 };
00089
00090
00091
00092
00093
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
00111
00112
00113 static void
00114 xdrstdio_destroy(xdrs)
00115 register XDR *xdrs;
00116 {
00117 (void)fflush((FILE *)xdrs->x_private);
00118
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
00200
00201
00202
00203
00204
00205
00206
00207 return (NULL);
00208 }