Annotation of 43BSDReno/lib/librpc/xdr_mem.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
                      3:  * unrestricted use provided that this legend is included on all tape
                      4:  * media and as a part of the software program in whole or part.  Users
                      5:  * may copy or modify Sun RPC without charge, but are not authorized
                      6:  * to license or distribute it to anyone else except as part of a product or
                      7:  * program developed by the user.
                      8:  * 
                      9:  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
                     10:  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
                     11:  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
                     12:  * 
                     13:  * Sun RPC is provided with no support and without any obligation on the
                     14:  * part of Sun Microsystems, Inc. to assist in its use, correction,
                     15:  * modification or enhancement.
                     16:  * 
                     17:  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
                     18:  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
                     19:  * OR ANY PART THEREOF.
                     20:  * 
                     21:  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
                     22:  * or profits or other special, indirect and consequential damages, even if
                     23:  * Sun has been advised of the possibility of such damages.
                     24:  * 
                     25:  * Sun Microsystems, Inc.
                     26:  * 2550 Garcia Avenue
                     27:  * Mountain View, California  94043
                     28:  */
                     29: #ifndef lint
                     30: static char sccsid[] = "@(#)xdr_mem.c 1.4 85/03/14 Copyr 1984 Sun Micro";
                     31: #endif
                     32: 
                     33: /*
                     34:  * xdr_mem.h, XDR implementation using memory buffers.
                     35:  *
                     36:  * Copyright (C) 1984, Sun Microsystems, Inc.
                     37:  *
                     38:  * If you have some data to be interpreted as external data representation
                     39:  * or to be converted to external data representation in a memory buffer,
                     40:  * then this is the package for you.
                     41:  *
                     42:  */
                     43: 
                     44: #include "types.h"
                     45: #include "xdr.h"
                     46: #include <netinet/in.h>
                     47: 
                     48: static bool_t  xdrmem_getlong();
                     49: static bool_t  xdrmem_putlong();
                     50: static bool_t  xdrmem_getbytes();
                     51: static bool_t  xdrmem_putbytes();
                     52: static u_int   xdrmem_getpos();
                     53: static bool_t  xdrmem_setpos();
                     54: static long *  xdrmem_inline();
                     55: static void    xdrmem_destroy();
                     56: 
                     57: static struct  xdr_ops xdrmem_ops = {
                     58:        xdrmem_getlong,
                     59:        xdrmem_putlong,
                     60:        xdrmem_getbytes,
                     61:        xdrmem_putbytes,
                     62:        xdrmem_getpos,
                     63:        xdrmem_setpos,
                     64:        xdrmem_inline,
                     65:        xdrmem_destroy
                     66: };
                     67: 
                     68: /*
                     69:  * The procedure xdrmem_create initializes a stream descriptor for a
                     70:  * memory buffer.  
                     71:  */
                     72: void
                     73: xdrmem_create(xdrs, addr, size, op)
                     74:        register XDR *xdrs;
                     75:        caddr_t addr;
                     76:        u_int size;
                     77:        enum xdr_op op;
                     78: {
                     79: 
                     80:        xdrs->x_op = op;
                     81:        xdrs->x_ops = &xdrmem_ops;
                     82:        xdrs->x_private = xdrs->x_base = addr;
                     83:        xdrs->x_handy = size;
                     84: }
                     85: 
                     86: static void
                     87: xdrmem_destroy(/*xdrs*/)
                     88:        /*XDR *xdrs;*/
                     89: {
                     90: }
                     91: 
                     92: static bool_t
                     93: xdrmem_getlong(xdrs, lp)
                     94:        register XDR *xdrs;
                     95:        long *lp;
                     96: {
                     97: 
                     98:        if ((xdrs->x_handy -= sizeof(long)) < 0)
                     99:                return (FALSE);
                    100:        *lp = ntohl(*((long *)(xdrs->x_private)));
                    101:        xdrs->x_private += sizeof(long);
                    102:        return (TRUE);
                    103: }
                    104: 
                    105: static bool_t
                    106: xdrmem_putlong(xdrs, lp)
                    107:        register XDR *xdrs;
                    108:        long *lp;
                    109: {
                    110: 
                    111:        if ((xdrs->x_handy -= sizeof(long)) < 0)
                    112:                return (FALSE);
                    113:        *(long *)xdrs->x_private = htonl(*lp);
                    114:        xdrs->x_private += sizeof(long);
                    115:        return (TRUE);
                    116: }
                    117: 
                    118: static bool_t
                    119: xdrmem_getbytes(xdrs, addr, len)
                    120:        register XDR *xdrs;
                    121:        caddr_t addr;
                    122:        register u_int len;
                    123: {
                    124: 
                    125:        if ((xdrs->x_handy -= len) < 0)
                    126:                return (FALSE);
                    127:        bcopy(xdrs->x_private, addr, len);
                    128:        xdrs->x_private += len;
                    129:        return (TRUE);
                    130: }
                    131: 
                    132: static bool_t
                    133: xdrmem_putbytes(xdrs, addr, len)
                    134:        register XDR *xdrs;
                    135:        caddr_t addr;
                    136:        register u_int len;
                    137: {
                    138: 
                    139:        if ((xdrs->x_handy -= len) < 0)
                    140:                return (FALSE);
                    141:        bcopy(addr, xdrs->x_private, len);
                    142:        xdrs->x_private += len;
                    143:        return (TRUE);
                    144: }
                    145: 
                    146: static u_int
                    147: xdrmem_getpos(xdrs)
                    148:        register XDR *xdrs;
                    149: {
                    150: 
                    151:        return ((u_int)xdrs->x_private - (u_int)xdrs->x_base);
                    152: }
                    153: 
                    154: static bool_t
                    155: xdrmem_setpos(xdrs, pos)
                    156:        register XDR *xdrs;
                    157:        u_int pos;
                    158: {
                    159:        register caddr_t newaddr = xdrs->x_base + pos;
                    160:        register caddr_t lastaddr = xdrs->x_private + xdrs->x_handy;
                    161: 
                    162:        if ((long)newaddr > (long)lastaddr)
                    163:                return (FALSE);
                    164:        xdrs->x_private = newaddr;
                    165:        xdrs->x_handy = (int)lastaddr - (int)newaddr;
                    166:        return (TRUE);
                    167: }
                    168: 
                    169: static long *
                    170: xdrmem_inline(xdrs, len)
                    171:        register XDR *xdrs;
                    172:        int len;
                    173: {
                    174:        long *buf = 0;
                    175: 
                    176:        if (xdrs->x_handy >= len) {
                    177:                xdrs->x_handy -= len;
                    178:                buf = (long *) xdrs->x_private;
                    179:                xdrs->x_private += len;
                    180:        }
                    181:        return (buf);
                    182: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.