🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.sys.sun
Article #11751

Re: xdr_char() routine

#11751
From: Viktor Dukhovni
Date: Wed, 29 Mar 1989 23:52
62 lines
2416 bytes
paquette@cpsc.ucalgary.ca (Trevor Paquette) writes:
>xdr_char(xdrs, ch)
>XDR *xdrs;
>char *ch;
>{
> char t[2];
> int ret;
>
> if(xdrs -> x_op == XDR_ENCODE)
>   {
>    t[0] = *ch;
>    t[1] = 0;
>    ret = xdr_string(xdrs, t, 1);
>   }
> else
>   {
>    ret = xdr_string(xdrs, t, 1);
>    *ch = t[0];
>   }
> return(ret);
>}

There are a couple of problems with this "replacement" for xdr_char:

1)  xdr_string,  like all xdr_rroutines,  expects a pointer to the object
being encoded/decoded.  So  xdr_string(xdrs,t,1)  is wrong!  You need a
char **.  Unfortunately the compiler won't let you take the address of an
array, arrays are *constant* pointers!

	If you want to use the above add
	char *p = t ;
	and call xdr_sting with
	xdr_string(xdrs,&p,...)

2) As well as encode and decode, xdrs->x_op could be XDR_FREE you should
probably pass that down to xdr_string() as you are doing, but it may be
better to leave poor ch alone when freeing args, particulary since p (You
have replaced t by &p) may not point anywhere useful!  So *ch = **p  may
get you a SIGSEGV.

3)  The iris may well have xdr_bytes(),  or xdr_opaque(),  either should
be able to give you better mileage than xdr_string, (No need to encode the
trailing null.  Also if you are already paying the penalty of passing
around integer length fields (=1 or 2) per character,  why not pass the
chars as ints!

	xdr_char(xdrs,p)
		XDR *xdrs ;
		u_char *p ; 	/* Lets not get messed up in sign murk */
	{
		int x = *p ;
		bool_t ret=xdr_int(xdrs,&x) ;
		if ( xdrs->x_op == XDR_DECODE )
			*p = x & 0377 ;  /* Don't need to be this anal */
		return ret ;
	}


Hope this helps.  It may be all be a late night dream,  but looks ok for
being typed on the fly.

	Viktor Dukhovni <viktor%fine@princeton.edu>
Technical Details
Message-ID: <6960@phoenix.Princeton.EDU>
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!husc6!rice!sun-spots-request
References: <785@cs-spool.calgary.UUCP>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!bloom-beacon!husc6!rice!sun-spots-request
From: viktor@cucumber.princeton.edu (Viktor Dukhovni)
Newsgroups: comp.sys.sun
Subject: Re: xdr_char() routine
Keywords: Software
Message-ID: <6960@phoenix.Princeton.EDU>
Date: 29 Mar 89 23:52:05 GMT
References: <785@cs-spool.calgary.UUCP>
Sender: usenet@rice.edu
Organization: princeton university
Lines: 62
Approved: Sun-Spots@rice.edu
Original-Date: 10 Mar 89 07:06:32 GMT
X-Sun-Spots-Digest: Volume 7, Issue 213, message 2 of 15
X-Issue-Reference: v7n188