From cdb3c81f36283df4b53f24a374d78c695e9d8b06 Mon Sep 17 00:00:00 2001
From: Eric Andersen <andersen@codepoet.org>
Date: Mon, 17 Jun 2002 21:12:16 +0000
Subject: Re-backport all the rpc stuff from glibc 2.2.5.  This allows us to
 make this junk (and I do mean that ;-) thread safe without undue pain.  Adds
 12k worth to the code size I'm afraid, but since I never use NFS and
 therefore never include this stuff, I guess thats acceptable.  I still need
 to enable the multi-threaded bits...  -Erik

---
 libc/inet/rpc/Makefile         |  24 +-
 libc/inet/rpc/auth_none.c      | 145 ++++---
 libc/inet/rpc/auth_unix.c      | 427 ++++++++++---------
 libc/inet/rpc/authunix_prot.c  |  52 +--
 libc/inet/rpc/bindresvport.c   |  77 ++--
 libc/inet/rpc/clnt_generic.c   | 194 ++++++---
 libc/inet/rpc/clnt_perror.c    | 555 +++++++++++++++---------
 libc/inet/rpc/clnt_raw.c       | 338 ++++++++-------
 libc/inet/rpc/clnt_simple.c    | 191 ++++++---
 libc/inet/rpc/clnt_tcp.c       | 775 ++++++++++++++++++---------------
 libc/inet/rpc/clnt_udp.c       | 851 +++++++++++++++++++++---------------
 libc/inet/rpc/clnt_unix.c      | 606 ++++++++++++++++++++++++++
 libc/inet/rpc/create_xid.c     |  64 +++
 libc/inet/rpc/errqueue.h       |  46 ++
 libc/inet/rpc/get_myaddress.c  | 127 +++---
 libc/inet/rpc/getrpcport.c     |  60 ++-
 libc/inet/rpc/pmap_clnt.c      | 189 +++++---
 libc/inet/rpc/pmap_getmaps.c   |  65 ++-
 libc/inet/rpc/pmap_getport.c   |  89 ++--
 libc/inet/rpc/pmap_prot.c      |  32 +-
 libc/inet/rpc/pmap_prot2.c     | 102 ++---
 libc/inet/rpc/pmap_rmt.c       | 615 +++++++++++++-------------
 libc/inet/rpc/rpc_callmsg.c    | 299 +++++++------
 libc/inet/rpc/rpc_commondata.c |  30 +-
 libc/inet/rpc/rpc_dtablesize.c |  31 +-
 libc/inet/rpc/rpc_prot.c       | 364 ++++++++--------
 libc/inet/rpc/rpc_thread.c     | 152 +++++++
 libc/inet/rpc/rtime.c          | 149 +++++++
 libc/inet/rpc/svc.c            | 730 +++++++++++++++----------------
 libc/inet/rpc/svc_auth.c       |  99 +++--
 libc/inet/rpc/svc_auth_unix.c  | 181 ++++----
 libc/inet/rpc/svc_raw.c        | 203 ++++-----
 libc/inet/rpc/svc_run.c        |  93 ++--
 libc/inet/rpc/svc_simple.c     | 241 ++++++-----
 libc/inet/rpc/svc_tcp.c        | 582 +++++++++++++------------
 libc/inet/rpc/svc_udp.c        | 782 ++++++++++++++++++++--------------
 libc/inet/rpc/svc_unix.c       | 533 +++++++++++++++++++++++
 libc/inet/rpc/xdr.c            | 880 +++++++++++++++++++++++---------------
 libc/inet/rpc/xdr_array.c      | 183 ++++----
 libc/inet/rpc/xdr_float.c      | 240 ++++++-----
 libc/inet/rpc/xdr_intXX_t.c    | 203 +++++++++
 libc/inet/rpc/xdr_mem.c        | 272 +++++++-----
 libc/inet/rpc/xdr_rec.c        | 947 ++++++++++++++++++++++-------------------
 libc/inet/rpc/xdr_reference.c  | 129 +++---
 libc/inet/rpc/xdr_stdio.c      | 210 ++++-----
 45 files changed, 8139 insertions(+), 5018 deletions(-)
 create mode 100644 libc/inet/rpc/clnt_unix.c
 create mode 100644 libc/inet/rpc/create_xid.c
 create mode 100644 libc/inet/rpc/errqueue.h
 create mode 100644 libc/inet/rpc/rpc_thread.c
 create mode 100644 libc/inet/rpc/rtime.c
 create mode 100644 libc/inet/rpc/svc_unix.c
 create mode 100644 libc/inet/rpc/xdr_intXX_t.c

(limited to 'libc/inet/rpc')

diff --git a/libc/inet/rpc/Makefile b/libc/inet/rpc/Makefile
index c27965ad9..3728c22a7 100644
--- a/libc/inet/rpc/Makefile
+++ b/libc/inet/rpc/Makefile
@@ -23,17 +23,19 @@
 
 TOPDIR=../../../
 include $(TOPDIR)Rules.mak
-
-CSRC = auth_none.c auth_unix.c authunix_prot.c \
-	bindresvport.c clnt_generic.c clnt_perror.c \
-	clnt_raw.c clnt_simple.c clnt_tcp.c clnt_udp.c \
-	get_myaddress.c getrpcent.c getrpcport.c pmap_clnt.c \
-	pmap_getmaps.c pmap_getport.c pmap_prot.c pmap_prot2.c \
-	pmap_rmt.c rpc_callmsg.c rpc_commondata.c \
-	rpc_dtablesize.c rpc_prot.c svc.c svc_auth.c \
-	svc_auth_unix.c svc_raw.c svc_run.c svc_simple.c \
-	svc_tcp.c svc_udp.c xdr.c xdr_array.c xdr_float.c \
-	xdr_mem.c xdr_rec.c xdr_reference.c xdr_stdio.c rcmd.c
+#CFLAGS+=-Werror
+
+CSRC :=auth_none.c auth_unix.c authunix_prot.c bindresvport.c \
+	clnt_generic.c clnt_perror.c clnt_raw.c clnt_simple.c clnt_tcp.c \
+	clnt_udp.c rpc_dtablesize.c get_myaddress.c getrpcent.c getrpcport.c \
+	pmap_clnt.c pmap_getmaps.c pmap_getport.c pmap_prot.c \
+	pmap_prot2.c pmap_rmt.c rpc_prot.c rpc_commondata.c rpc_callmsg.c \
+	svc.c svc_auth.c svc_auth_unix.c svc_raw.c svc_run.c svc_simple.c \
+	svc_tcp.c svc_udp.c xdr.c xdr_array.c xdr_float.c xdr_mem.c \
+	xdr_rec.c xdr_reference.c xdr_stdio.c \
+	rtime.c clnt_unix.c svc_unix.c create_xid.c xdr_intXX_t.c rcmd.c \
+	rpc_thread.c
+#openchild.c xdr_sizeof.c
 COBJS=$(patsubst %.c,%.o, $(CSRC))
 OBJS=$(COBJS)
 
diff --git a/libc/inet/rpc/auth_none.c b/libc/inet/rpc/auth_none.c
index 08cc1940e..0983b9532 100644
--- a/libc/inet/rpc/auth_none.c
+++ b/libc/inet/rpc/auth_none.c
@@ -1,4 +1,3 @@
-/* @(#)auth_none.c	2.1 88/07/29 4.0 RPCSRC */
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -6,120 +5,128 @@
  * may copy or modify Sun RPC without charge, but are not authorized
  * to license or distribute it to anyone else except as part of a product or
  * program developed by the user.
- * 
+ *
  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- * 
+ *
  * Sun RPC is provided with no support and without any obligation on the
  * part of Sun Microsystems, Inc. to assist in its use, correction,
  * modification or enhancement.
- * 
+ *
  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  * OR ANY PART THEREOF.
- * 
+ *
  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  * or profits or other special, indirect and consequential damages, even if
  * Sun has been advised of the possibility of such damages.
- * 
+ *
  * Sun Microsystems, Inc.
  * 2550 Garcia Avenue
  * Mountain View, California  94043
  */
-#define __FORCE_GLIBC
-#include <features.h>
-
+/*
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
 /*
  * auth_none.c
- * Creates a client authentication handle for passing "null" 
- * credentials and verifiers to remote systems. 
- * 
- * Copyright (C) 1984, Sun Microsystems, Inc. 
+ * Creates a client authentication handle for passing "null"
+ * credentials and verifiers to remote systems.
  */
 
-#include <rpc/types.h>
-#include <rpc/xdr.h>
-#include <rpc/auth.h>
+#include <rpc/rpc.h>
+
 #define MAX_MARSHEL_SIZE 20
 
 /*
  * Authenticator operations routines
  */
-static void authnone_verf();
-static void authnone_destroy();
-static bool_t authnone_marshal();
-static bool_t authnone_validate();
-static bool_t authnone_refresh();
+static void authnone_verf (AUTH *);
+static void authnone_destroy (AUTH *);
+static bool_t authnone_marshal (AUTH *, XDR *);
+static bool_t authnone_validate (AUTH *, struct opaque_auth *);
+static bool_t authnone_refresh (AUTH *);
 
 static struct auth_ops ops = {
-	authnone_verf,
-	authnone_marshal,
-	authnone_validate,
-	authnone_refresh,
-	authnone_destroy
+  authnone_verf,
+  authnone_marshal,
+  authnone_validate,
+  authnone_refresh,
+  authnone_destroy
 };
 
-static struct authnone_private {
-	AUTH no_client;
-	char marshalled_client[MAX_MARSHEL_SIZE];
-	u_int mcnt;
-} *authnone_private;
+struct authnone_private_s {
+  AUTH no_client;
+  char marshalled_client[MAX_MARSHEL_SIZE];
+  u_int mcnt;
+};
+#ifdef _RPC_THREAD_SAFE_
+#define authnone_private ((struct authnone_private_s *)RPC_THREAD_VARIABLE(authnone_private_s))
+#else
+static struct authnone_private_s *authnone_private;
+#endif
 
-AUTH *authnone_create()
+AUTH *
+authnone_create (void)
 {
-	register struct authnone_private *ap = authnone_private;
-	XDR xdr_stream;
-	register XDR *xdrs;
+  struct authnone_private_s *ap;
+  XDR xdr_stream;
+  XDR *xdrs;
 
-	if (ap == 0) {
-		ap = (struct authnone_private *) calloc(1, sizeof(*ap));
-		if (ap == 0)
-			return (0);
-		authnone_private = ap;
-	}
-	if (!ap->mcnt) {
-		ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
-		ap->no_client.ah_ops = &ops;
-		xdrs = &xdr_stream;
-		xdrmem_create(xdrs, ap->marshalled_client,
-					  (u_int) MAX_MARSHEL_SIZE, XDR_ENCODE);
-		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_cred);
-		(void) xdr_opaque_auth(xdrs, &ap->no_client.ah_verf);
-		ap->mcnt = XDR_GETPOS(xdrs);
-		XDR_DESTROY(xdrs);
-	}
-	return (&ap->no_client);
+  ap = (struct authnone_private_s *) authnone_private;
+  if (ap == NULL)
+    {
+      ap = (struct authnone_private_s *) calloc (1, sizeof (*ap));
+      if (ap == NULL)
+	return NULL;
+      authnone_private = ap;
+    }
+  if (!ap->mcnt)
+    {
+      ap->no_client.ah_cred = ap->no_client.ah_verf = _null_auth;
+      ap->no_client.ah_ops = &ops;
+      xdrs = &xdr_stream;
+      xdrmem_create (xdrs, ap->marshalled_client, (u_int) MAX_MARSHEL_SIZE,
+		     XDR_ENCODE);
+      (void) xdr_opaque_auth (xdrs, &ap->no_client.ah_cred);
+      (void) xdr_opaque_auth (xdrs, &ap->no_client.ah_verf);
+      ap->mcnt = XDR_GETPOS (xdrs);
+      XDR_DESTROY (xdrs);
+    }
+  return (&ap->no_client);
 }
 
- /*ARGSUSED*/ static bool_t authnone_marshal(client, xdrs)
-AUTH *client;
-XDR *xdrs;
+/*ARGSUSED */
+static bool_t
+authnone_marshal (AUTH *client, XDR *xdrs)
 {
-	register struct authnone_private *ap = authnone_private;
+  struct authnone_private_s *ap;
 
-	if (ap == 0)
-		return (0);
-	return ((*xdrs->x_ops->x_putbytes) (xdrs,
-										ap->marshalled_client, ap->mcnt));
+  ap = (struct authnone_private_s *) authnone_private;
+  if (ap == NULL)
+    return FALSE;
+  return (*xdrs->x_ops->x_putbytes) (xdrs, ap->marshalled_client, ap->mcnt);
 }
 
-static void authnone_verf()
+static void
+authnone_verf (AUTH *auth)
 {
 }
 
-static bool_t authnone_validate()
+static bool_t
+authnone_validate (AUTH *auth, struct opaque_auth *oa)
 {
-
-	return (TRUE);
+  return TRUE;
 }
 
-static bool_t authnone_refresh()
+static bool_t
+authnone_refresh (AUTH *auth)
 {
-
-	return (FALSE);
+  return FALSE;
 }
 
-static void authnone_destroy()
+static void
+authnone_destroy (AUTH *auth)
 {
 }
diff --git a/libc/inet/rpc/auth_unix.c b/libc/inet/rpc/auth_unix.c
index 003763003..3e14ba2a5 100644
--- a/libc/inet/rpc/auth_unix.c
+++ b/libc/inet/rpc/auth_unix.c
@@ -1,4 +1,3 @@
-/* @(#)auth_unix.c	2.2 88/08/01 4.0 RPCSRC */
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -6,11 +5,11 @@
  * may copy or modify Sun RPC without charge, but are not authorized
  * to license or distribute it to anyone else except as part of a product or
  * program developed by the user.
- * 
+ *
  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- * 
+ *
  * Sun RPC is provided with no support and without any obligation on the
  * part of Sun Microsystems, Inc. to assist in its use, correction,
  * modification or enhancement.
@@ -18,293 +17,309 @@
  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  * OR ANY PART THEREOF.
- * 
+ *
  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  * or profits or other special, indirect and consequential damages, even if
  * Sun has been advised of the possibility of such damages.
- * 
+ *
  * Sun Microsystems, Inc.
  * 2550 Garcia Avenue
  * Mountain View, California  94043
  */
-#define __FORCE_GLIBC
-#include <features.h>
-
 /*
- * auth_unix.c, Implements UNIX style authentication parameters. 
- *  
  * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
+/*
+ * auth_unix.c, Implements UNIX style authentication parameters.
  *
  * The system is very weak.  The client uses no encryption for it's
  * credentials and only sends null verifiers.  The server sends backs
  * null verifiers or optionally a verifier that suggests a new short hand
  * for the credentials.
- *
  */
 
+#define __FORCE_GLIBC
+#include <features.h>
+
+#include <limits.h>
 #include <stdio.h>
-#include <unistd.h>
-#include <sys/types.h>
 #include <string.h>
+#include <unistd.h>
+#include <sys/param.h>
 
 #include <rpc/types.h>
 #include <rpc/xdr.h>
 #include <rpc/auth.h>
 #include <rpc/auth_unix.h>
 
+#ifdef USE_IN_LIBIO
+# include <wchar.h>
+#endif
+
 /*
  * Unix authenticator operations vector
  */
-static void authunix_nextverf();
-static bool_t authunix_marshal();
-static bool_t authunix_validate();
-static bool_t authunix_refresh();
-static void authunix_destroy();
+static void authunix_nextverf (AUTH *);
+static bool_t authunix_marshal (AUTH *, XDR *);
+static bool_t authunix_validate (AUTH *, struct opaque_auth *);
+static bool_t authunix_refresh (AUTH *);
+static void authunix_destroy (AUTH *);
 
 static struct auth_ops auth_unix_ops = {
-	authunix_nextverf,
-	authunix_marshal,
-	authunix_validate,
-	authunix_refresh,
-	authunix_destroy
+  authunix_nextverf,
+  authunix_marshal,
+  authunix_validate,
+  authunix_refresh,
+  authunix_destroy
 };
 
 /*
  * This struct is pointed to by the ah_private field of an auth_handle.
  */
 struct audata {
-	struct opaque_auth au_origcred;	/* original credentials */
-	struct opaque_auth au_shcred;	/* short hand cred */
-	u_long au_shfaults;			/* short hand cache faults */
-	char au_marshed[MAX_AUTH_BYTES];
-	u_int au_mpos;				/* xdr pos at end of marshed */
+  struct opaque_auth au_origcred;	/* original credentials */
+  struct opaque_auth au_shcred;	/* short hand cred */
+  u_long au_shfaults;		/* short hand cache faults */
+  char au_marshed[MAX_AUTH_BYTES];
+  u_int au_mpos;		/* xdr pos at end of marshed */
 };
-
 #define	AUTH_PRIVATE(auth)	((struct audata *)auth->ah_private)
 
-static void marshal_new_auth();
+static bool_t marshal_new_auth (AUTH *) internal_function;
 
 
 /*
  * Create a unix style authenticator.
  * Returns an auth handle with the given stuff in it.
  */
-AUTH *authunix_create __P ((char *machname, uid_t uid,
-				   gid_t gid, int len,
-				   gid_t *aup_gids))
+AUTH *
+authunix_create (char *machname, uid_t uid, gid_t gid, int len,
+		 gid_t *aup_gids)
 {
-	struct authunix_parms aup;
-	char mymem[MAX_AUTH_BYTES];
-	struct timeval now;
-	XDR xdrs;
-	register AUTH *auth;
-	register struct audata *au;
-
-	/*
-	 * Allocate and set up auth handle
-	 */
-	auth = (AUTH *) mem_alloc(sizeof(*auth));
-#ifndef KERNEL
-	if (auth == NULL) {
-		(void) fprintf(stderr, "authunix_create: out of memory\n");
-		return (NULL);
-	}
-#endif
-	au = (struct audata *) mem_alloc(sizeof(*au));
-#ifndef KERNEL
-	if (au == NULL) {
-		(void) fprintf(stderr, "authunix_create: out of memory\n");
-		return (NULL);
-	}
-#endif
-	auth->ah_ops = &auth_unix_ops;
-	auth->ah_private = (caddr_t) au;
-	auth->ah_verf = au->au_shcred = _null_auth;
-	au->au_shfaults = 0;
-
-	/*
-	 * fill in param struct from the given params
-	 */
-	(void) gettimeofday(&now, (struct timezone *) 0);
-	aup.aup_time = now.tv_sec;
-	aup.aup_machname = machname;
-	aup.aup_uid = uid;
-	aup.aup_gid = gid;
-	aup.aup_len = (u_int) len;
-	aup.aup_gids = aup_gids;
-
-	/*
-	 * Serialize the parameters into origcred
-	 */
-	xdrmem_create(&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
-	if (!xdr_authunix_parms(&xdrs, &aup))
-		abort();
-	au->au_origcred.oa_length = len = XDR_GETPOS(&xdrs);
-	au->au_origcred.oa_flavor = AUTH_UNIX;
-#ifdef KERNEL
-	au->au_origcred.oa_base = mem_alloc((u_int) len);
-#else
-	if ((au->au_origcred.oa_base = mem_alloc((u_int) len)) == NULL) {
-		(void) fprintf(stderr, "authunix_create: out of memory\n");
-		return (NULL);
-	}
+  struct authunix_parms aup;
+  char mymem[MAX_AUTH_BYTES];
+  struct timeval now;
+  XDR xdrs;
+  AUTH *auth;
+  struct audata *au;
+
+  /*
+   * Allocate and set up auth handle
+   */
+  auth = (AUTH *) mem_alloc (sizeof (*auth));
+  au = (struct audata *) mem_alloc (sizeof (*au));
+  if (auth == NULL || au == NULL)
+    {
+no_memory:
+#ifdef USE_IN_LIBIO
+      if (_IO_fwide (stderr, 0) > 0)
+	(void) __fwprintf (stderr, L"%s",
+			   _("authunix_create: out of memory\n"));
+      else
 #endif
-	bcopy(mymem, au->au_origcred.oa_base, (u_int) len);
-
-	/*
-	 * set auth handle to reflect new cred.
-	 */
-	auth->ah_cred = au->au_origcred;
-	marshal_new_auth(auth);
-	return (auth);
+	(void) fputs (_("authunix_create: out of memory\n"), stderr);
+      mem_free (auth, sizeof (*auth));
+      mem_free (au, sizeof (*au));
+      return NULL;
+    }
+  auth->ah_ops = &auth_unix_ops;
+  auth->ah_private = (caddr_t) au;
+  auth->ah_verf = au->au_shcred = _null_auth;
+  au->au_shfaults = 0;
+
+  /*
+   * fill in param struct from the given params
+   */
+  (void) gettimeofday (&now, (struct timezone *) 0);
+  aup.aup_time = now.tv_sec;
+  aup.aup_machname = machname;
+  aup.aup_uid = uid;
+  aup.aup_gid = gid;
+  aup.aup_len = (u_int) len;
+  aup.aup_gids = aup_gids;
+
+  /*
+   * Serialize the parameters into origcred
+   */
+  xdrmem_create (&xdrs, mymem, MAX_AUTH_BYTES, XDR_ENCODE);
+  if (!xdr_authunix_parms (&xdrs, &aup))
+    abort ();
+  au->au_origcred.oa_length = len = XDR_GETPOS (&xdrs);
+  au->au_origcred.oa_flavor = AUTH_UNIX;
+  au->au_origcred.oa_base = mem_alloc ((u_int) len);
+  if (au->au_origcred.oa_base == NULL)
+    goto no_memory;
+  memcpy(au->au_origcred.oa_base, mymem, (u_int) len);
+
+  /*
+   * set auth handle to reflect new cred.
+   */
+  auth->ah_cred = au->au_origcred;
+  marshal_new_auth (auth);
+  return auth;
 }
 
 /*
  * Returns an auth handle with parameters determined by doing lots of
  * syscalls.
  */
-AUTH *authunix_create_default()
+AUTH *
+authunix_create_default (void)
 {
-	register int len;
-	char machname[MAX_MACHINE_NAME + 1];
-	register int uid;
-	register int gid;
-	int gids[NGRPS];
-
-	if (gethostname(machname, MAX_MACHINE_NAME) == -1)
-		abort();
-	machname[MAX_MACHINE_NAME] = 0;
-	uid = geteuid();
-	gid = getegid();
-	if ((len = getgroups(NGRPS, gids)) < 0)
-		abort();
-	return (authunix_create(machname, uid, gid, len, gids));
+  int len;
+  char machname[MAX_MACHINE_NAME + 1];
+  uid_t uid;
+  gid_t gid;
+  int max_nr_groups = sysconf (_SC_NGROUPS_MAX);
+  gid_t gids[max_nr_groups];
+
+  if (gethostname (machname, MAX_MACHINE_NAME) == -1)
+    abort ();
+  machname[MAX_MACHINE_NAME] = 0;
+  uid = geteuid ();
+  gid = getegid ();
+
+  if ((len = getgroups (max_nr_groups, gids)) < 0)
+    abort ();
+  /* This braindamaged Sun code forces us here to truncate the
+     list of groups to NGRPS members since the code in
+     authuxprot.c transforms a fixed array.  Grrr.  */
+  return authunix_create (machname, uid, gid, MIN (NGRPS, len), gids);
 }
 
 /*
  * authunix operations
  */
 
-static void authunix_nextverf(auth)
-AUTH *auth;
+static void
+authunix_nextverf (AUTH *auth)
 {
-	/* no action necessary */
+  /* no action necessary */
 }
 
-static bool_t authunix_marshal(auth, xdrs)
-AUTH *auth;
-XDR *xdrs;
+static bool_t
+authunix_marshal (AUTH *auth, XDR *xdrs)
 {
-	register struct audata *au = AUTH_PRIVATE(auth);
+  struct audata *au = AUTH_PRIVATE (auth);
 
-	return (XDR_PUTBYTES(xdrs, au->au_marshed, au->au_mpos));
+  return XDR_PUTBYTES (xdrs, au->au_marshed, au->au_mpos);
 }
 
-static bool_t authunix_validate(auth, verf)
-register AUTH *auth;
-struct opaque_auth verf;
+static bool_t
+authunix_validate (AUTH *auth, struct opaque_auth *verf)
 {
-	register struct audata *au;
-	XDR xdrs;
-
-	if (verf.oa_flavor == AUTH_SHORT) {
-		au = AUTH_PRIVATE(auth);
-		xdrmem_create(&xdrs, verf.oa_base, verf.oa_length, XDR_DECODE);
-
-		if (au->au_shcred.oa_base != NULL) {
-			mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);
-			au->au_shcred.oa_base = NULL;
-		}
-		if (xdr_opaque_auth(&xdrs, &au->au_shcred)) {
-			auth->ah_cred = au->au_shcred;
-		} else {
-			xdrs.x_op = XDR_FREE;
-			(void) xdr_opaque_auth(&xdrs, &au->au_shcred);
-			au->au_shcred.oa_base = NULL;
-			auth->ah_cred = au->au_origcred;
-		}
-		marshal_new_auth(auth);
+  struct audata *au;
+  XDR xdrs;
+
+  if (verf->oa_flavor == AUTH_SHORT)
+    {
+      au = AUTH_PRIVATE (auth);
+      xdrmem_create (&xdrs, verf->oa_base, verf->oa_length,
+		     XDR_DECODE);
+
+      if (au->au_shcred.oa_base != NULL)
+	{
+	  mem_free (au->au_shcred.oa_base,
+		    au->au_shcred.oa_length);
+	  au->au_shcred.oa_base = NULL;
 	}
-	return (TRUE);
+      if (xdr_opaque_auth (&xdrs, &au->au_shcred))
+	{
+	  auth->ah_cred = au->au_shcred;
+	}
+      else
+	{
+	  xdrs.x_op = XDR_FREE;
+	  (void) xdr_opaque_auth (&xdrs, &au->au_shcred);
+	  au->au_shcred.oa_base = NULL;
+	  auth->ah_cred = au->au_origcred;
+	}
+      marshal_new_auth (auth);
+    }
+  return TRUE;
 }
 
-static bool_t authunix_refresh(auth)
-register AUTH *auth;
+static bool_t
+authunix_refresh (AUTH *auth)
 {
-	register struct audata *au = AUTH_PRIVATE(auth);
-	struct authunix_parms aup;
-	struct timeval now;
-	XDR xdrs;
-	register int stat;
-
-	if (auth->ah_cred.oa_base == au->au_origcred.oa_base) {
-		/* there is no hope.  Punt */
-		return (FALSE);
-	}
-	au->au_shfaults++;
-
-	/* first deserialize the creds back into a struct authunix_parms */
-	aup.aup_machname = NULL;
-	aup.aup_gids = (int *) NULL;
-	xdrmem_create(&xdrs, au->au_origcred.oa_base,
-				  au->au_origcred.oa_length, XDR_DECODE);
-	stat = xdr_authunix_parms(&xdrs, &aup);
-	if (!stat)
-		goto done;
-
-	/* update the time and serialize in place */
-	(void) gettimeofday(&now, (struct timezone *) 0);
-	aup.aup_time = now.tv_sec;
-	xdrs.x_op = XDR_ENCODE;
-	XDR_SETPOS(&xdrs, 0);
-	stat = xdr_authunix_parms(&xdrs, &aup);
-	if (!stat)
-		goto done;
-	auth->ah_cred = au->au_origcred;
-	marshal_new_auth(auth);
-  done:
-	/* free the struct authunix_parms created by deserializing */
-	xdrs.x_op = XDR_FREE;
-	(void) xdr_authunix_parms(&xdrs, &aup);
-	XDR_DESTROY(&xdrs);
-	return (stat);
+  struct audata *au = AUTH_PRIVATE (auth);
+  struct authunix_parms aup;
+  struct timeval now;
+  XDR xdrs;
+  int stat;
+
+  if (auth->ah_cred.oa_base == au->au_origcred.oa_base)
+    {
+      /* there is no hope.  Punt */
+      return FALSE;
+    }
+  au->au_shfaults++;
+
+  /* first deserialize the creds back into a struct authunix_parms */
+  aup.aup_machname = NULL;
+  aup.aup_gids = (gid_t *) NULL;
+  xdrmem_create (&xdrs, au->au_origcred.oa_base,
+		 au->au_origcred.oa_length, XDR_DECODE);
+  stat = xdr_authunix_parms (&xdrs, &aup);
+  if (!stat)
+    goto done;
+
+  /* update the time and serialize in place */
+  (void) gettimeofday (&now, (struct timezone *) 0);
+  aup.aup_time = now.tv_sec;
+  xdrs.x_op = XDR_ENCODE;
+  XDR_SETPOS (&xdrs, 0);
+  stat = xdr_authunix_parms (&xdrs, &aup);
+  if (!stat)
+    goto done;
+  auth->ah_cred = au->au_origcred;
+  marshal_new_auth (auth);
+done:
+  /* free the struct authunix_parms created by deserializing */
+  xdrs.x_op = XDR_FREE;
+  (void) xdr_authunix_parms (&xdrs, &aup);
+  XDR_DESTROY (&xdrs);
+  return stat;
 }
 
-static void authunix_destroy(auth)
-register AUTH *auth;
+static void
+authunix_destroy (AUTH *auth)
 {
-	register struct audata *au = AUTH_PRIVATE(auth);
+  struct audata *au = AUTH_PRIVATE (auth);
 
-	mem_free(au->au_origcred.oa_base, au->au_origcred.oa_length);
+  mem_free (au->au_origcred.oa_base, au->au_origcred.oa_length);
 
-	if (au->au_shcred.oa_base != NULL)
-		mem_free(au->au_shcred.oa_base, au->au_shcred.oa_length);
+  if (au->au_shcred.oa_base != NULL)
+    mem_free (au->au_shcred.oa_base, au->au_shcred.oa_length);
 
-	mem_free(auth->ah_private, sizeof(struct audata));
+  mem_free (auth->ah_private, sizeof (struct audata));
 
-	if (auth->ah_verf.oa_base != NULL)
-		mem_free(auth->ah_verf.oa_base, auth->ah_verf.oa_length);
+  if (auth->ah_verf.oa_base != NULL)
+    mem_free (auth->ah_verf.oa_base, auth->ah_verf.oa_length);
 
-	mem_free((caddr_t) auth, sizeof(*auth));
+  mem_free ((caddr_t) auth, sizeof (*auth));
 }
 
 /*
  * Marshals (pre-serializes) an auth struct.
  * sets private data, au_marshed and au_mpos
  */
-static void marshal_new_auth(auth)
-register AUTH *auth;
+static bool_t
+internal_function
+marshal_new_auth (AUTH *auth)
 {
-	XDR xdr_stream;
-	register XDR *xdrs = &xdr_stream;
-	register struct audata *au = AUTH_PRIVATE(auth);
-
-	xdrmem_create(xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE);
-	if ((!xdr_opaque_auth(xdrs, &(auth->ah_cred))) ||
-		(!xdr_opaque_auth(xdrs, &(auth->ah_verf)))) {
-		perror("auth_none.c - Fatal marshalling problem");
-	} else {
-		au->au_mpos = XDR_GETPOS(xdrs);
-	}
-	XDR_DESTROY(xdrs);
+  XDR xdr_stream;
+  XDR *xdrs = &xdr_stream;
+  struct audata *au = AUTH_PRIVATE (auth);
+
+  xdrmem_create (xdrs, au->au_marshed, MAX_AUTH_BYTES, XDR_ENCODE);
+  if ((!xdr_opaque_auth (xdrs, &(auth->ah_cred))) ||
+      (!xdr_opaque_auth (xdrs, &(auth->ah_verf))))
+    perror (_("auth_none.c - Fatal marshalling problem"));
+  else
+    au->au_mpos = XDR_GETPOS (xdrs);
+
+  XDR_DESTROY (xdrs);
+
+  return TRUE;
 }
diff --git a/libc/inet/rpc/authunix_prot.c b/libc/inet/rpc/authunix_prot.c
index e3ad64644..b033c568a 100644
--- a/libc/inet/rpc/authunix_prot.c
+++ b/libc/inet/rpc/authunix_prot.c
@@ -1,4 +1,3 @@
-/* @(#)authunix_prot.c	2.1 88/07/29 4.0 RPCSRC */
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -6,38 +5,35 @@
  * may copy or modify Sun RPC without charge, but are not authorized
  * to license or distribute it to anyone else except as part of a product or
  * program developed by the user.
- * 
+ *
  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- * 
+ *
  * Sun RPC is provided with no support and without any obligation on the
  * part of Sun Microsystems, Inc. to assist in its use, correction,
  * modification or enhancement.
- * 
+ *
  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  * OR ANY PART THEREOF.
- * 
+ *
  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  * or profits or other special, indirect and consequential damages, even if
  * Sun has been advised of the possibility of such damages.
- * 
+ *
  * Sun Microsystems, Inc.
  * 2550 Garcia Avenue
  * Mountain View, California  94043
  */
-#define __FORCE_GLIBC
-#include <features.h>
-
+/*
+ * Copyright (C) 1984, Sun Microsystems, Inc.
+ */
 /*
  * authunix_prot.c
  * XDR for UNIX style authentication parameters for RPC
- *
- * Copyright (C) 1984, Sun Microsystems, Inc.
  */
 
-
 #include <rpc/types.h>
 #include <rpc/xdr.h>
 #include <rpc/auth.h>
@@ -45,19 +41,25 @@
 
 /*
  * XDR for unix authentication parameters.
+ * Unfortunately, none of these can be declared const.
  */
-bool_t xdr_authunix_parms(xdrs, p)
-register XDR *xdrs;
-register struct authunix_parms *p;
+bool_t
+xdr_authunix_parms (XDR * xdrs, struct authunix_parms *p)
 {
-
-	if (xdr_u_long(xdrs, &(p->aup_time))
-		&& xdr_string(xdrs, &(p->aup_machname), MAX_MACHINE_NAME)
-		&& xdr_int(xdrs, &(p->aup_uid))
-		&& xdr_int(xdrs, &(p->aup_gid))
-		&& xdr_array(xdrs, (caddr_t *) & (p->aup_gids),
-					 &(p->aup_len), NGRPS, sizeof(int), (xdrproc_t) xdr_int)) {
-		return (TRUE);
-	}
-	return (FALSE);
+  if (xdr_u_long (xdrs, &(p->aup_time))
+      && xdr_string (xdrs, &(p->aup_machname), MAX_MACHINE_NAME)
+      && (sizeof (uid_t) == sizeof (short int)
+	  ? xdr_u_short (xdrs, (u_short *) & (p->aup_uid))
+	  : xdr_u_int (xdrs, (u_int *) & (p->aup_uid)))
+      && (sizeof (gid_t) == sizeof (short int)
+	  ? xdr_u_short (xdrs, (u_short *) & (p->aup_gid))
+	  : xdr_u_int (xdrs, (u_int *) & (p->aup_gid)))
+      && xdr_array (xdrs, (caddr_t *) & (p->aup_gids),
+		    & (p->aup_len), NGRPS, sizeof (gid_t),
+		      (sizeof (gid_t) == sizeof (short int)
+		       ? (xdrproc_t) xdr_u_short : (xdrproc_t) xdr_u_int)))
+    {
+      return TRUE;
+    }
+  return FALSE;
 }
diff --git a/libc/inet/rpc/bindresvport.c b/libc/inet/rpc/bindresvport.c
index 752360232..7dcebe7dc 100644
--- a/libc/inet/rpc/bindresvport.c
+++ b/libc/inet/rpc/bindresvport.c
@@ -5,77 +5,84 @@
  * may copy or modify Sun RPC without charge, but are not authorized
  * to license or distribute it to anyone else except as part of a product or
  * program developed by the user.
- * 
+ *
  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- * 
+ *
  * Sun RPC is provided with no support and without any obligation on the
  * part of Sun Microsystems, Inc. to assist in its use, correction,
  * modification or enhancement.
- * 
+ *
  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  * OR ANY PART THEREOF.
- * 
+ *
  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  * or profits or other special, indirect and consequential damages, even if
  * Sun has been advised of the possibility of such damages.
- * 
+ *
  * Sun Microsystems, Inc.
  * 2550 Garcia Avenue
  * Mountain View, California  94043
  */
-
 /*
  * Copyright (c) 1987 by Sun Microsystems, Inc.
  */
 
 #define __FORCE_GLIBC
 #include <features.h>
+
+#include <errno.h>
 #include <unistd.h>
 #include <string.h>
 #include <sys/types.h>
-#include <sys/errno.h>
 #include <sys/socket.h>
 #include <netinet/in.h>
 
 /*
  * Bind a socket to a privileged IP port
  */
-int bindresvport(sd, sin)
-int sd;
-struct sockaddr_in *sin;
+int
+bindresvport (int sd, struct sockaddr_in *sin)
 {
-	int res;
-	static short port;
-	struct sockaddr_in myaddr;
-	extern int errno;
-	int i;
+  int res;
+  static short port;
+  struct sockaddr_in myaddr;
+  int i;
 
 #define STARTPORT 600
 #define ENDPORT (IPPORT_RESERVED - 1)
 #define NPORTS	(ENDPORT - STARTPORT + 1)
 
-	if (sin == (struct sockaddr_in *) 0) {
-		sin = &myaddr;
-		bzero(sin, sizeof(*sin));
-		sin->sin_family = AF_INET;
-	} else if (sin->sin_family != AF_INET) {
-		__set_errno(EPFNOSUPPORT);
-		return (-1);
-	}
-	if (port == 0) {
-		port = (getpid() % NPORTS) + STARTPORT;
-	}
-	res = -1;
-	__set_errno(EADDRINUSE);
-	for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; i++) {
-		sin->sin_port = htons(port++);
-		if (port > ENDPORT) {
-			port = STARTPORT;
-		}
-		res = bind(sd, (struct sockaddr *)sin, (socklen_t)sizeof(struct sockaddr_in));
+  if (sin == (struct sockaddr_in *) 0)
+    {
+      sin = &myaddr;
+      bzero (sin, sizeof (*sin));
+      sin->sin_family = AF_INET;
+    }
+  else if (sin->sin_family != AF_INET)
+    {
+      __set_errno (EPFNOSUPPORT);
+      return -1;
+    }
+
+  if (port == 0)
+    {
+      port = (getpid () % NPORTS) + STARTPORT;
+    }
+  res = -1;
+  __set_errno (EADDRINUSE);
+
+  for (i = 0; i < NPORTS && res < 0 && errno == EADDRINUSE; ++i)
+    {
+      sin->sin_port = htons (port++);
+      if (port > ENDPORT)
+	{
+	  port = STARTPORT;
 	}
-	return (res);
+      res = bind(sd, (struct sockaddr *)sin, sizeof(struct sockaddr_in));
+    }
+
+  return res;
 }
diff --git a/libc/inet/rpc/clnt_generic.c b/libc/inet/rpc/clnt_generic.c
index 5b4b5997f..79df33113 100644
--- a/libc/inet/rpc/clnt_generic.c
+++ b/libc/inet/rpc/clnt_generic.c
@@ -1,4 +1,3 @@
-/* @(#)clnt_generic.c	2.2 88/08/01 4.0 RPCSRC */
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
  * unrestricted use provided that this legend is included on all tape
@@ -6,11 +5,11 @@
  * may copy or modify Sun RPC without charge, but are not authorized
  * to license or distribute it to anyone else except as part of a product or
  * program developed by the user.
- * 
+ *
  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- * 
+ *
  * Sun RPC is provided with no support and without any obligation on the
  * part of Sun Microsystems, Inc. to assist in its use, correction,
  * modification or enhancement.
@@ -18,20 +17,25 @@
  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  * OR ANY PART THEREOF.
- * 
+ *
  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  * or profits or other special, indirect and consequential damages, even if
  * Sun has been advised of the possibility of such damages.
- * 
+ *
  * Sun Microsystems, Inc.
  * 2550 Garcia Avenue
  * Mountain View, California  94043
  */
-#define __FORCE_GLIBC
-#include <features.h>
 /*
  * Copyright (C) 1987, Sun Microsystems, Inc.
  */
+
+#define __FORCE_GLIBC
+#include <features.h>
+
+#include <alloca.h>
+#include <errno.h>
+#include <string.h>
 #include <rpc/rpc.h>
 #include <sys/socket.h>
 #include <sys/errno.h>
@@ -39,72 +43,126 @@
 
 /*
  * Generic client creation: takes (hostname, program-number, protocol) and
- * returns client handle. Default options are set, which the user can 
+ * returns client handle. Default options are set, which the user can
  * change using the rpc equivalent of ioctl()'s.
  */
-CLIENT *clnt_create __P ((const char *hostname, const u_long prog,
-				 const u_long vers, const char *proto))
+CLIENT *
+clnt_create (const char *hostname, u_long prog, u_long vers,
+	     const char *proto)
 {
-	struct hostent *h;
-	struct protoent *p;
-	struct sockaddr_in sin;
-	int sock;
-	struct timeval tv;
-	CLIENT *client;
+  struct hostent hostbuf, *h;
+  size_t hstbuflen;
+  char *hsttmpbuf;
+  struct protoent *p;
+  struct sockaddr_in sin;
+  struct sockaddr_un sun;
+  int sock;
+  struct timeval tv;
+  CLIENT *client;
+  int herr;
 
-	h = gethostbyname(hostname);
-	if (h == NULL) {
-		rpc_createerr.cf_stat = RPC_UNKNOWNHOST;
-		return (NULL);
-	}
-	if (h->h_addrtype != AF_INET) {
-		/*
-		 * Only support INET for now
-		 */
-		rpc_createerr.cf_stat = RPC_SYSTEMERROR;
-		rpc_createerr.cf_error.re_errno = EAFNOSUPPORT;
-		return (NULL);
-	}
-#ifdef __linux__
-	bzero((char *) &sin, sizeof(sin));
-#endif
-	sin.sin_family = h->h_addrtype;
-	sin.sin_port = 0;
-#ifndef __linux__
-	bzero(sin.sin_zero, sizeof(sin.sin_zero));
+  if (strcmp (proto, "unix") == 0)
+    {
+      bzero ((char *)&sun, sizeof (sun));
+      sun.sun_family = AF_UNIX;
+      strcpy (sun.sun_path, hostname);
+      sock = RPC_ANYSOCK;
+      client = clntunix_create (&sun, prog, vers, &sock, 0, 0);
+      if (client == NULL)
+	return NULL;
+#if 0
+      /* This is not wanted.  This would disable the user from having
+	 a timeout in the clnt_call() call.  Only a call to cnlt_control()
+	 by the user should set the timeout value.  */
+      tv.tv_sec = 25;
+      tv.tv_usec = 0;
+      clnt_control (client, CLSET_TIMEOUT, (char *)&tv);
 #endif
-	bcopy(h->h_addr, (char *) &sin.sin_addr, h->h_length);
-	p = getprotobyname(proto);
-	if (p == NULL) {
-		rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
-		rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
-		return (NULL);
+      return client;
+    }
+
+  hstbuflen = 1024;
+  hsttmpbuf = alloca (hstbuflen);
+  while (gethostbyname_r (hostname, &hostbuf, hsttmpbuf, hstbuflen,
+			    &h, &herr) != 0
+	 || h == NULL)
+    if (herr != NETDB_INTERNAL || errno != ERANGE)
+      {
+	get_rpc_createerr().cf_stat = RPC_UNKNOWNHOST;
+	return NULL;
+      }
+    else
+      {
+	/* Enlarge the buffer.  */
+	hstbuflen *= 2;
+	hsttmpbuf = alloca (hstbuflen);
+      }
+
+  if (h->h_addrtype != AF_INET)
+    {
+      /*
+       * Only support INET for now
+       */
+      struct rpc_createerr *ce = &get_rpc_createerr ();
+      ce->cf_stat = RPC_SYSTEMERROR;
+      ce->cf_error.re_errno = EAFNOSUPPORT;
+      return NULL;
+    }
+  sin.sin_family = h->h_addrtype;
+  sin.sin_port = 0;
+  bzero (sin.sin_zero, sizeof (sin.sin_zero));
+  memcpy ((char *) &sin.sin_addr, h->h_addr, h->h_length);
+
+#warning getprotobyname is not reentrant...  Add getprotobyname_r
+  p = getprotobyname(proto);
+  if (p == NULL) {
+      struct rpc_createerr *ce = &get_rpc_createerr ();
+      ce->cf_stat = RPC_UNKNOWNPROTO;
+      ce->cf_error.re_errno = EPFNOSUPPORT;
+      return NULL;
+  }
+
+  sock = RPC_ANYSOCK;
+  switch (p->p_proto)
+    {
+    case IPPROTO_UDP:
+      tv.tv_sec = 5;
+      tv.tv_usec = 0;
+      client = clntudp_create (&sin, prog, vers, tv, &sock);
+      if (client == NULL)
+	{
+	  return NULL;
 	}
-	sock = RPC_ANYSOCK;
-	switch (p->p_proto) {
-	case IPPROTO_UDP:
-		tv.tv_sec = 5;
-		tv.tv_usec = 0;
-		client = clntudp_create(&sin, prog, vers, tv, &sock);
-		if (client == NULL) {
-			return (NULL);
-		}
-		tv.tv_sec = 25;
-		clnt_control(client, CLSET_TIMEOUT, (char*)&tv);
-		break;
-	case IPPROTO_TCP:
-		client = clnttcp_create(&sin, prog, vers, &sock, 0, 0);
-		if (client == NULL) {
-			return (NULL);
-		}
-		tv.tv_sec = 25;
-		tv.tv_usec = 0;
-		clnt_control(client, CLSET_TIMEOUT, (char*)&tv);
-		break;
-	default:
-		rpc_createerr.cf_stat = RPC_SYSTEMERROR;
-		rpc_createerr.cf_error.re_errno = EPFNOSUPPORT;
-		return (NULL);
+#if 0
+      /* This is not wanted.  This would disable the user from having
+	 a timeout in the clnt_call() call.  Only a call to cnlt_control()
+	 by the user should set the timeout value.  */
+      tv.tv_sec = 25;
+      clnt_control (client, CLSET_TIMEOUT, (char *)&tv);
+#endif
+      break;
+    case IPPROTO_TCP:
+      client = clnttcp_create (&sin, prog, vers, &sock, 0, 0);
+      if (client == NULL)
+	{
+	  return NULL;
 	}
-	return (client);
+#if 0
+      /* This is not wanted.  This would disable the user from having
+	 a timeout in the clnt_call() call.  Only a call to cnlt_control()
+	 by the user should set the timeout value.  */
+      tv.tv_sec = 25;
+      tv.tv_usec = 0;
+      clnt_control (client, CLSET_TIMEOUT, (char *)&tv);
+#endif
+      break;
+    default:
+      {
+	struct rpc_createerr *ce = &get_rpc_createerr ();
+	ce->cf_stat = RPC_SYSTEMERROR;
+	ce->cf_error.re_errno = EPFNOSUPPORT;
+      }
+      return (NULL);
+    }
+  return client;
 }
diff --git a/libc/inet/rpc/clnt_perror.c b/libc/inet/rpc/clnt_perror.c
index a4d173707..3d5e6b217 100644
--- a/libc/inet/rpc/clnt_perror.c
+++ b/libc/inet/rpc/clnt_perror.c
@@ -6,29 +6,30 @@
  * may copy or modify Sun RPC without charge, but are not authorized
  * to license or distribute it to anyone else except as part of a product or
  * program developed by the user.
- * 
+ *
  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- * 
+ *
  * Sun RPC is provided with no support and without any obligation on the
  * part of Sun Microsystems, Inc. to assist in its use, correction,
  * modification or enhancement.
- * 
+ *
  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  * OR ANY PART THEREOF.
- * 
+ *
  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  * or profits or other special, indirect and consequential damages, even if
  * Sun has been advised of the possibility of such damages.
- * 
+ *
  * Sun Microsystems, Inc.
  * 2550 Garcia Avenue
  * Mountain View, California  94043
  */
-#define __FORCE_GLIBC
-#include <features.h>
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)clnt_perror.c 1.15 87/10/07 Copyr 1984 Sun Micro";
+#endif
 
 /*
  * clnt_perror.c
@@ -36,254 +37,396 @@
  * Copyright (C) 1984, Sun Microsystems, Inc.
  *
  */
+#define __FORCE_GLIBC
+#include <features.h>
 
 #include <stdio.h>
 #include <string.h>
+#include <rpc/rpc.h>
 
-#include <rpc/types.h>
-#include <rpc/auth.h>
-#include <rpc/clnt.h>
-
-static char *auth_errmsg();
+#ifdef USE_IN_LIBIO
+# include <wchar.h>
+# include <libio/iolibio.h>
+# define fputs(s, f) _IO_fputs (s, f)
+#endif
 
-extern char *strcpy();
+static char *auth_errmsg (enum auth_stat stat) internal_function;
 
+#ifdef _RPC_THREAD_SAFE_
+/*
+ * Making buf a preprocessor macro requires renaming the local
+ * buf variable in a few functions.  Overriding a global variable
+ * with a local variable of the same name is a bad idea, anyway.
+ */
+#define buf ((char *)RPC_THREAD_VARIABLE(clnt_perr_buf_s))
+#else
 static char *buf;
+#endif
 
-static char *_buf()
+static char *
+_buf (void)
 {
-
-	if (buf == 0)
-		buf = (char *) malloc(256);
-	return (buf);
+  if (buf == NULL)
+    buf = (char *) malloc (256);
+  return buf;
 }
 
 /*
  * Print reply error info
  */
-char *clnt_sperror __P ((CLIENT *rpch, const char *s))
+char *
+clnt_sperror (CLIENT * rpch, const char *msg)
 {
-	struct rpc_err e;
-	void clnt_perrno();
-	char *err;
-	char *str = _buf();
-	char *strstart = str;
-
-	if (str == 0)
-		return (0);
-	CLNT_GETERR(rpch, &e);
-
-	(void) sprintf(str, "%s: ", s);
-	str += strlen(str);
-
-	(void) strcpy(str, clnt_sperrno(e.re_status));
-	str += strlen(str);
-
-	switch (e.re_status) {
-	case RPC_SUCCESS:
-	case RPC_CANTENCODEARGS:
-	case RPC_CANTDECODERES:
-	case RPC_TIMEDOUT:
-	case RPC_PROGUNAVAIL:
-	case RPC_PROCUNAVAIL:
-	case RPC_CANTDECODEARGS:
-	case RPC_SYSTEMERROR:
-	case RPC_UNKNOWNHOST:
-	case RPC_UNKNOWNPROTO:
-	case RPC_PMAPFAILURE:
-	case RPC_PROGNOTREGISTERED:
-	case RPC_FAILED:
-		break;
-
-	case RPC_CANTSEND:
-	case RPC_CANTRECV:
-		(void) sprintf(str, "; errno = %s", strerror (e.re_errno));
-		str += strlen(str);
-		break;
-
-	case RPC_VERSMISMATCH:
-		(void) sprintf(str,
-					   "; low version = %lu, high version = %lu",
-					   e.re_vers.low, e.re_vers.high);
-		str += strlen(str);
-		break;
-
-	case RPC_AUTHERROR:
-		err = auth_errmsg(e.re_why);
-		(void) sprintf(str, "; why = ");
-		str += strlen(str);
-		if (err != NULL) {
-			(void) sprintf(str, "%s", err);
-		} else {
-			(void) sprintf(str,
-						   "(unknown authentication error - %d)",
-						   (int) e.re_why);
-		}
-		str += strlen(str);
-		break;
-
-	case RPC_PROGVERSMISMATCH:
-		(void) sprintf(str,
-					   "; low version = %lu, high version = %lu",
-					   e.re_vers.low, e.re_vers.high);
-		str += strlen(str);
-		break;
-
-	default:					/* unknown */
-		(void) sprintf(str,
-					   "; s1 = %lu, s2 = %lu", e.re_lb.s1, e.re_lb.s2);
-		str += strlen(str);
-		break;
+  char chrbuf[1024];
+  struct rpc_err e;
+  char *err;
+  char *str = _buf ();
+  char *strstart = str;
+  int len;
+
+  if (str == NULL)
+    return NULL;
+  CLNT_GETERR (rpch, &e);
+
+  len = sprintf (str, "%s: ", msg);
+  str += len;
+
+  (void) strcpy(str, clnt_sperrno(e.re_status));
+  str += strlen(str);
+
+  switch (e.re_status)
+    {
+    case RPC_SUCCESS:
+    case RPC_CANTENCODEARGS:
+    case RPC_CANTDECODERES:
+    case RPC_TIMEDOUT:
+    case RPC_PROGUNAVAIL:
+    case RPC_PROCUNAVAIL:
+    case RPC_CANTDECODEARGS:
+    case RPC_SYSTEMERROR:
+    case RPC_UNKNOWNHOST:
+    case RPC_UNKNOWNPROTO:
+    case RPC_PMAPFAILURE:
+    case RPC_PROGNOTREGISTERED:
+    case RPC_FAILED:
+      break;
+
+    case RPC_CANTSEND:
+    case RPC_CANTRECV:
+      strerror_r (e.re_errno, chrbuf, sizeof chrbuf);
+      len = sprintf (str, "; errno = %s", chrbuf); 
+      str += len;
+      break;
+
+    case RPC_VERSMISMATCH:
+      len= sprintf (str, _("; low version = %lu, high version = %lu"),
+		    e.re_vers.low, e.re_vers.high);
+      str += len;
+      break;
+
+    case RPC_AUTHERROR:
+      err = auth_errmsg (e.re_why);
+      (void) strcpy(str, _("; why = "));
+      str += strlen(str);
+
+      if (err != NULL)
+	{
+	  (void) strcpy(str, err);
+	  str += strlen(str);
+	}
+      else
+	{
+	  len = sprintf (str, _("(unknown authentication error - %d)"),
+			 (int) e.re_why);
+	  str += len;
 	}
-	(void) sprintf(str, "\n");
-	return (strstart);
+      break;
+
+    case RPC_PROGVERSMISMATCH:
+      len = sprintf (str, _("; low version = %lu, high version = %lu"),
+		     e.re_vers.low, e.re_vers.high);
+      str += len;
+      break;
+
+    default:			/* unknown */
+      len = sprintf (str, "; s1 = %lu, s2 = %lu", e.re_lb.s1, e.re_lb.s2);
+      str += len;
+      break;
+    }
+  *str = '\n';
+  *++str = '\0';
+  return (strstart);
 }
 
-void clnt_perror __P ((CLIENT *rpch, const char *s))
+void
+clnt_perror (CLIENT * rpch, const char *msg)
 {
-	(void) fprintf(stderr, "%s", clnt_sperror(rpch, s));
+#ifdef USE_IN_LIBIO
+  if (_IO_fwide (stderr, 0) > 0)
+    (void) __fwprintf (stderr, L"%s", clnt_sperror (rpch, msg));
+  else
+#endif
+    (void) fputs (clnt_sperror (rpch, msg), stderr);
 }
 
 
-struct rpc_errtab {
-	enum clnt_stat status;
-	char *message;
+struct rpc_errtab
+{
+  enum clnt_stat status;
+  unsigned int message_off;
 };
 
-#if 0
-static struct rpc_errtab rpc_errlist[] = {
-	{RPC_SUCCESS,
-	 "RPC: Success"},
-	{RPC_CANTENCODEARGS,
-	 "RPC: Can't encode arguments"},
-	{RPC_CANTDECODERES,
-	 "RPC: Can't decode result"},
-	{RPC_CANTSEND,
-	 "RPC: Unable to send"},
-	{RPC_CANTRECV,
-	 "RPC: Unable to receive"},
-	{RPC_TIMEDOUT,
-	 "RPC: Timed out"},
-	{RPC_VERSMISMATCH,
-	 "RPC: Incompatible versions of RPC"},
-	{RPC_AUTHERROR,
-	 "RPC: Authentication error"},
-	{RPC_PROGUNAVAIL,
-	 "RPC: Program unavailable"},
-	{RPC_PROGVERSMISMATCH,
-	 "RPC: Program/version mismatch"},
-	{RPC_PROCUNAVAIL,
-	 "RPC: Procedure unavailable"},
-	{RPC_CANTDECODEARGS,
-	 "RPC: Server can't decode arguments"},
-	{RPC_SYSTEMERROR,
-	 "RPC: Remote system error"},
-	{RPC_UNKNOWNHOST,
-	 "RPC: Unknown host"},
-	{RPC_UNKNOWNPROTO,
-	 "RPC: Unknown protocol"},
-	{RPC_PMAPFAILURE,
-	 "RPC: Port mapper failure"},
-	{RPC_PROGNOTREGISTERED,
-	 "RPC: Program not registered"},
-	{RPC_FAILED,
-	 "RPC: Failed (unspecified error)"}
+static const char rpc_errstr[] =
+{
+#define RPC_SUCCESS_IDX		0
+  _("RPC: Success")
+  "\0"
+#define RPC_CANTENCODEARGS_IDX	(RPC_SUCCESS_IDX + sizeof "RPC: Success")
+  _("RPC: Can't encode arguments")
+  "\0"
+#define RPC_CANTDECODERES_IDX	(RPC_CANTENCODEARGS_IDX \
+				 + sizeof "RPC: Can't encode arguments")
+  _("RPC: Can't decode result")
+  "\0"
+#define RPC_CANTSEND_IDX	(RPC_CANTDECODERES_IDX \
+				 + sizeof "RPC: Can't decode result")
+  _("RPC: Unable to send")
+  "\0"
+#define RPC_CANTRECV_IDX	(RPC_CANTSEND_IDX \
+				 + sizeof "RPC: Unable to send")
+  _("RPC: Unable to receive")
+  "\0"
+#define RPC_TIMEDOUT_IDX	(RPC_CANTRECV_IDX \
+				 + sizeof "RPC: Unable to receive")
+  _("RPC: Timed out")
+  "\0"
+#define RPC_VERSMISMATCH_IDX	(RPC_TIMEDOUT_IDX \
+				 + sizeof "RPC: Timed out")
+  _("RPC: Incompatible versions of RPC")
+  "\0"
+#define RPC_AUTHERROR_IDX	(RPC_VERSMISMATCH_IDX \
+				 + sizeof "RPC: Incompatible versions of RPC")
+  _("RPC: Authentication error")
+  "\0"
+#define RPC_PROGUNAVAIL_IDX		(RPC_AUTHERROR_IDX \
+				 + sizeof "RPC: Authentication error")
+  _("RPC: Program unavailable")
+  "\0"
+#define RPC_PROGVERSMISMATCH_IDX (RPC_PROGUNAVAIL_IDX \
+				  + sizeof "RPC: Program unavailable")
+  _("RPC: Program/version mismatch")
+  "\0"
+#define RPC_PROCUNAVAIL_IDX	(RPC_PROGVERSMISMATCH_IDX \
+				 + sizeof "RPC: Program/version mismatch")
+  _("RPC: Procedure unavailable")
+  "\0"
+#define RPC_CANTDECODEARGS_IDX	(RPC_PROCUNAVAIL_IDX \
+				 + sizeof "RPC: Procedure unavailable")
+  _("RPC: Server can't decode arguments")
+  "\0"
+#define RPC_SYSTEMERROR_IDX	(RPC_CANTDECODEARGS_IDX \
+				 + sizeof "RPC: Server can't decode arguments")
+  _("RPC: Remote system error")
+  "\0"
+#define RPC_UNKNOWNHOST_IDX	(RPC_SYSTEMERROR_IDX \
+				 + sizeof "RPC: Remote system error")
+  _("RPC: Unknown host")
+  "\0"
+#define RPC_UNKNOWNPROTO_IDX	(RPC_UNKNOWNHOST_IDX \
+				 + sizeof "RPC: Unknown host")
+  _("RPC: Unknown protocol")
+  "\0"
+#define RPC_PMAPFAILURE_IDX	(RPC_UNKNOWNPROTO_IDX \
+				 + sizeof "RPC: Unknown protocol")
+  _("RPC: Port mapper failure")
+  "\0"
+#define RPC_PROGNOTREGISTERED_IDX (RPC_PMAPFAILURE_IDX \
+				   + sizeof "RPC: Port mapper failure")
+  _("RPC: Program not registered")
+  "\0"
+#define RPC_FAILED_IDX		(RPC_PROGNOTREGISTERED_IDX \
+				 + sizeof "RPC: Program not registered")
+  _("RPC: Failed (unspecified error)")
 };
-#endif
+
+static const struct rpc_errtab rpc_errlist[] =
+{
+  { RPC_SUCCESS, RPC_SUCCESS_IDX },
+  { RPC_CANTENCODEARGS, RPC_CANTENCODEARGS_IDX },
+  { RPC_CANTDECODERES, RPC_CANTDECODERES_IDX },
+  { RPC_CANTSEND, RPC_CANTSEND_IDX },
+  { RPC_CANTRECV, RPC_CANTRECV_IDX },
+  { RPC_TIMEDOUT, RPC_TIMEDOUT_IDX },
+  { RPC_VERSMISMATCH, RPC_VERSMISMATCH_IDX },
+  { RPC_AUTHERROR, RPC_AUTHERROR_IDX },
+  { RPC_PROGUNAVAIL, RPC_PROGUNAVAIL_IDX },
+  { RPC_PROGVERSMISMATCH, RPC_PROGVERSMISMATCH_IDX },
+  { RPC_PROCUNAVAIL, RPC_PROCUNAVAIL_IDX },
+  { RPC_CANTDECODEARGS, RPC_CANTDECODEARGS_IDX },
+  { RPC_SYSTEMERROR, RPC_SYSTEMERROR_IDX },
+  { RPC_UNKNOWNHOST, RPC_UNKNOWNHOST_IDX },
+  { RPC_UNKNOWNPROTO, RPC_UNKNOWNPROTO_IDX },
+  { RPC_PMAPFAILURE, RPC_PMAPFAILURE_IDX },
+  { RPC_PROGNOTREGISTERED, RPC_PROGNOTREGISTERED_IDX },
+  { RPC_FAILED, RPC_FAILED_IDX }
+};
+
 
 /*
  * This interface for use by clntrpc
  */
-char *clnt_sperrno(stat)
-enum clnt_stat stat;
+char *
+clnt_sperrno (enum clnt_stat stat)
 {
-#if 0
-	int i;
+  size_t i;
 
-	for (i = 0; i < sizeof(rpc_errlist) / sizeof(struct rpc_errtab); i++) {
-		if (rpc_errlist[i].status == stat) {
-			return (rpc_errlist[i].message);
-		}
+  for (i = 0; i < sizeof (rpc_errlist) / sizeof (struct rpc_errtab); i++)
+    {
+      if (rpc_errlist[i].status == stat)
+	{
+	  return (char*)_(rpc_errstr + rpc_errlist[i].message_off);
 	}
-#endif
-	return ("RPC: (unknown error code)");
+    }
+  return _("RPC: (unknown error code)");
 }
 
-void clnt_perrno(num)
-enum clnt_stat num;
+void
+clnt_perrno (enum clnt_stat num)
 {
-	(void) fprintf(stderr, "%s", clnt_sperrno(num));
+#ifdef USE_IN_LIBIO
+  if (_IO_fwide (stderr, 0) > 0)
+    (void) __fwprintf (stderr, L"%s", clnt_sperrno (num));
+  else
+#endif
+    (void) fputs (clnt_sperrno (num), stderr);
 }
 
 
-char *clnt_spcreateerror __P ((__const char *s))
+char *
+clnt_spcreateerror (const char *msg)
 {
-#if 0
-	char *str = _buf();
-
-	if (str == 0)
-		return (0);
-	(void) sprintf(str, "%s: ", s);
-	(void) strcat(str, clnt_sperrno(rpc_createerr.cf_stat));
-	switch (rpc_createerr.cf_stat) {
-	case RPC_PMAPFAILURE:
-		(void) strcat(str, " - ");
-		(void) strcat(str, clnt_sperrno(rpc_createerr.cf_error.re_status));
-		break;
-
-	case RPC_SYSTEMERROR:
-		(void) strcat(str, " - ");
-		if (rpc_createerr.cf_error.re_errno > 0)
-			(void) strcat(str, strerror (rpc_createerr.cf_error.re_errno));
-		else
-			(void )sprintf(&str[strlen(str)], "Error %d",
-				       rpc_createerr.cf_error.re_errno);
-		break;
-	}
-	(void) strcat(str, "\n");
-	return (str);
-#endif
-	return(0);
+  char chrbuf[1024];
+  char *str = _buf ();
+  char *cp;
+  int len;
+  struct rpc_createerr *ce;
+
+  if (str == NULL)
+    return NULL;
+  ce = &get_rpc_createerr ();
+  len = sprintf (str, "%s: ", msg);
+  cp = str + len;
+  (void) strcpy(cp, clnt_sperrno (ce->cf_stat));
+  cp += strlen(cp);
+
+  switch (ce->cf_stat)
+    {
+    case RPC_PMAPFAILURE:
+      (void) strcpy(cp, " - ");
+      cp += strlen(cp);
+
+      (void) strcpy(cp, clnt_sperrno (ce->cf_error.re_status));
+      cp += strlen(cp);
+
+      break;
+
+    case RPC_SYSTEMERROR:
+      (void) strcpy(cp, " - ");
+      cp += strlen(cp);
+
+      strerror_r (ce->cf_error.re_errno, chrbuf, sizeof chrbuf);
+      (void) strcpy(cp, chrbuf);
+      cp += strlen(cp);
+      break;
+    default:
+      break;
+    }
+  *cp = '\n';
+  *++cp = '\0';
+  return str;
 }
 
-extern void clnt_pcreateerror __P ((__const char *s))
+void
+clnt_pcreateerror (const char *msg)
 {
-	(void) fprintf(stderr, "%s", clnt_spcreateerror(s));
+#ifdef USE_IN_LIBIO
+  if (_IO_fwide (stderr, 0) > 0)
+    (void) __fwprintf (stderr, L"%s", clnt_spcreateerror (msg));
+  else
+#endif
+    (void) fputs (clnt_spcreateerror (msg), stderr);
 }
 
-struct auth_errtab {
-	enum auth_stat status;
-	char *message;
+struct auth_errtab
+{
+  enum auth_stat status;
+  unsigned int message_off;
 };
 
-static struct auth_errtab auth_errlist[] = {
-	{AUTH_OK,
-	 "Authentication OK"},
-	{AUTH_BADCRED,
-	 "Invalid client credential"},
-	{AUTH_REJECTEDCRED,
-	 "Server rejected credential"},
-	{AUTH_BADVERF,
-	 "Invalid client verifier"},
-	{AUTH_REJECTEDVERF,
-	 "Server rejected verifier"},
-	{AUTH_TOOWEAK,
-	 "Client credential too weak"},
-	{AUTH_INVALIDRESP,
-	 "Invalid server verifier"},
-	{AUTH_FAILED,
-	 "Failed (unspecified error)"},
+static const char auth_errstr[] =
+{
+#define AUTH_OK_IDX		0
+   _("Authentication OK")
+   "\0"
+#define AUTH_BADCRED_IDX	(AUTH_OK_IDX + sizeof "Authentication OK")
+   _("Invalid client credential")
+   "\0"
+#define AUTH_REJECTEDCRED_IDX	(AUTH_BADCRED_IDX \
+				 + sizeof "Invalid client credential")
+   _("Server rejected credential")
+   "\0"
+#define AUTH_BADVERF_IDX	(AUTH_REJECTEDCRED_IDX \
+				 + sizeof "Server rejected credential")
+   _("Invalid client verifier")
+   "\0"
+#define AUTH_REJECTEDVERF_IDX	(AUTH_BADVERF_IDX \
+				 + sizeof "Invalid client verifier")
+   _("Server rejected verifier")
+   "\0"
+#define AUTH_TOOWEAK_IDX	(AUTH_REJECTEDVERF_IDX \
+				 + sizeof "Server rejected verifier")
+   _("Client credential too weak")
+   "\0"
+#define AUTH_INVALIDRESP_IDX	(AUTH_TOOWEAK_IDX \
+				 + sizeof "Client credential too weak")
+   _("Invalid server verifier")
+   "\0"
+#define AUTH_FAILED_IDX		(AUTH_INVALIDRESP_IDX \
+				 + sizeof "Invalid server verifier")
+   _("Failed (unspecified error)")
+};
+
+static const struct auth_errtab auth_errlist[] =
+{
+  { AUTH_OK, AUTH_OK_IDX },
+  { AUTH_BADCRED, AUTH_BADCRED_IDX },
+  { AUTH_REJECTEDCRED, AUTH_REJECTEDCRED_IDX },
+  { AUTH_BADVERF, AUTH_BADVERF_IDX },
+  { AUTH_REJECTEDVERF, AUTH_REJECTEDVERF_IDX },
+  { AUTH_TOOWEAK, AUTH_TOOWEAK_IDX },
+  { AUTH_INVALIDRESP, AUTH_INVALIDRESP_IDX },
+  { AUTH_FAILED, AUTH_FAILED_IDX }
 };
 
-static char *auth_errmsg(stat)
-enum auth_stat stat;
+static char *
+internal_function
+auth_errmsg (enum auth_stat stat)
 {
-	int i;
+  size_t i;
 
-	for (i = 0; i < sizeof(auth_errlist) / sizeof(struct auth_errtab); i++) {
-		if (auth_errlist[i].status == stat) {
-			return (auth_errlist[i].message);
-		}
+  for (i = 0; i < sizeof (auth_errlist) / sizeof (struct auth_errtab); i++)
+    {
+      if (auth_errlist[i].status == stat)
+	{
+	  return (char*)_(auth_errstr + auth_errlist[i].message_off);
 	}
-	return (NULL);
+    }
+  return NULL;
+}
+
+
+static void __attribute__ ((unused))
+free_mem (void)
+{
+  free (buf);
 }
diff --git a/libc/inet/rpc/clnt_raw.c b/libc/inet/rpc/clnt_raw.c
index b10db18b6..0d424523e 100644
--- a/libc/inet/rpc/clnt_raw.c
+++ b/libc/inet/rpc/clnt_raw.c
@@ -6,11 +6,11 @@
  * may copy or modify Sun RPC without charge, but are not authorized
  * to license or distribute it to anyone else except as part of a product or
  * program developed by the user.
- * 
+ *
  * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
  * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
  * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
- * 
+ *
  * Sun RPC is provided with no support and without any obligation on the
  * part of Sun Microsystems, Inc. to assist in its use, correction,
  * modification or enhancement.
@@ -18,17 +18,18 @@
  * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
  * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
  * OR ANY PART THEREOF.
- * 
+ *
  * In no event will Sun Microsystems, Inc. be liable for any lost revenue
  * or profits or other special, indirect and consequential damages, even if
  * Sun has been advised of the possibility of such damages.
- * 
+ *
  * Sun Microsystems, Inc.
  * 2550 Garcia Avenue
  * Mountain View, California  94043
  */
-#define __FORCE_GLIBC
-#include <features.h>
+#if !defined(lint) && defined(SCCSIDS)
+static char sccsid[] = "@(#)clnt_raw.c 1.22 87/08/11 Copyr 1984 Sun Micro";
+#endif
 
 /*
  * clnt_raw.c
@@ -37,193 +38,216 @@
  *
  * Memory based rpc for simple testing and timing.
  * Interface to create an rpc client and server in the same process.
- * This lets us similate rpc and get round trip overhead, without
- * any interference from the kernal.
+ * This lets us simulate rpc and get round trip overhead, without
+ * any interference from the kernel.
  */
 
 #include <rpc/rpc.h>
+#include <rpc/svc.h>
+#include <rpc/xdr.h>
 
 #define MCALL_MSG_SIZE 24
 
 /*
  * This is the "network" we will be moving stuff over.
  */
-static struct clntraw_private {
-	CLIENT client_object;
-	XDR xdr_stream;
-	char _raw_buf[UDPMSGSIZE];
-	char mashl_callmsg[MCALL_MSG_SIZE];
-	u_int mcnt;
-} *clntraw_private;
-
-static enum clnt_stat clntraw_call();
-static void clntraw_abort();
-static void clntraw_geterr();
-static bool_t clntraw_freeres();
-static bool_t clntraw_control();
-static void clntraw_destroy();
-
-static struct clnt_ops client_ops = {
-	clntraw_call,
-	clntraw_abort,
-	clntraw_geterr,
-	clntraw_freeres,
-	clntraw_destroy,
-	clntraw_control
+struct clntraw_private_s
+  {
+    CLIENT client_object;
+    XDR xdr_stream;
+    char _raw_buf[UDPMSGSIZE];
+    char mashl_callmsg[MCALL_MSG_SIZE];
+    u_int mcnt;
+  };
+#ifdef _RPC_THREAD_SAFE_
+#define clntraw_private ((struct clntraw_private_s *)RPC_THREAD_VARIABLE(clntraw_private_s))
+#else
+static struct clntraw_private_s *clntraw_private;
+#endif
+
+static enum clnt_stat clntraw_call (CLIENT *, u_long, xdrproc_t, caddr_t,
+				    xdrproc_t, caddr_t, struct timeval);
+static void clntraw_abort (void);
+static void clntraw_geterr (CLIENT *, struct rpc_err *);
+static bool_t clntraw_freeres (CLIENT *, xdrproc_t, caddr_t);
+static bool_t clntraw_control (CLIENT *, int, char *);
+static void clntraw_destroy (CLIENT *);
+
+static struct clnt_ops client_ops =
+{
+  clntraw_call,
+  clntraw_abort,
+  clntraw_geterr,
+  clntraw_freeres,
+  clntraw_destroy,
+  clntraw_control
 };
 
-void svc_getreq();
-
 /*
  * Create a client handle for memory based rpc.
  */
-CLIENT *clntraw_create(prog, vers)
-u_long prog;
-u_long vers;
+CLIENT *
+clntraw_create (u_long prog, u_long vers)
 {
-	register struct clntraw_private *clp = clntraw_private;
-	struct rpc_msg call_msg;
-	XDR *xdrs = &clp->xdr_stream;
-	CLIENT *client = &clp->client_object;
-
-	if (clp == 0) {
-		clp = (struct clntraw_private *) calloc(1, sizeof(*clp));
-		if (clp == 0)
-			return (0);
-		clntraw_private = clp;
-	}
-	/*
-	 * pre-serialize the staic part of the call msg and stash it away
-	 */
-	call_msg.rm_direction = CALL;
-	call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
-	call_msg.rm_call.cb_prog = prog;
-	call_msg.rm_call.cb_vers = vers;
-	xdrmem_create(xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
-	if (!xdr_callhdr(xdrs, &call_msg)) {
-		perror("clnt_raw.c - Fatal header serialization error.");
-	}
-	clp->mcnt = XDR_GETPOS(xdrs);
-	XDR_DESTROY(xdrs);
-
-	/*
-	 * Set xdrmem for client/server shared buffer
-	 */
-	xdrmem_create(xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
-
-	/*
-	 * create client handle
-	 */
-	client->cl_ops = &client_ops;
-	client->cl_auth = authnone_create();
-	return (client);
+  struct clntraw_private_s *clp = clntraw_private;
+  struct rpc_msg call_msg;
+  XDR *xdrs = &clp->xdr_stream;
+  CLIENT *client = &clp->client_object;
+
+  if (clp == 0)
+    {
+      clp = (struct clntraw_private_s *) calloc (1, sizeof (*clp));
+      if (clp == 0)
+	return (0);
+      clntraw_private = clp;
+    }
+  /*
+   * pre-serialize the static part of the call msg and stash it away
+   */
+  call_msg.rm_direction = CALL;
+  call_msg.rm_call.cb_rpcvers = RPC_MSG_VERSION;
+  call_msg.rm_call.cb_prog = prog;
+  call_msg.rm_call.cb_vers = vers;
+  xdrmem_create (xdrs, clp->mashl_callmsg, MCALL_MSG_SIZE, XDR_ENCODE);
+  if (!xdr_callhdr (xdrs, &call_msg))
+    {
+      perror (_ ("clnt_raw.c - Fatal header serialization error."));
+    }
+  clp->mcnt = XDR_GETPOS (xdrs);
+  XDR_DESTROY (xdrs);
+
+  /*
+   * Set xdrmem for client/server shared buffer
+   */
+  xdrmem_create (xdrs, clp->_raw_buf, UDPMSGSIZE, XDR_FREE);
+
+  /*
+   * create client handle
+   */
+  client->cl_ops = &client_ops;
+  client->cl_auth = authnone_create ();
+  return client;
 }
 
 static enum clnt_stat
-clntraw_call(h, proc, xargs, argsp, xresults, resultsp, timeout)
-CLIENT *h;
-u_long proc;
-xdrproc_t xargs;
-caddr_t argsp;
-xdrproc_t xresults;
-caddr_t resultsp;
-struct timeval timeout;
+clntraw_call (h, proc, xargs, argsp, xresults, resultsp, timeout)
+     CLIENT *h;
+     u_long proc;
+     xdrproc_t xargs;
+     caddr_t argsp;
+     xdrproc_t xresults;
+     caddr_t resultsp;
+     struct timeval timeout;
 {
-	register struct clntraw_private *clp = clntraw_private;
-	register XDR *xdrs = &clp->xdr_stream;
-	struct rpc_msg msg;
-	enum clnt_stat status;
-	struct rpc_err error;
-
-	if (clp == 0)
-		return (RPC_FAILED);
-  call_again:
-	/*
-	 * send request
-	 */
-	xdrs->x_op = XDR_ENCODE;
-	XDR_SETPOS(xdrs, 0);
-	((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
-	if ((!XDR_PUTBYTES(xdrs, clp->mashl_callmsg, clp->mcnt)) ||
-		(!XDR_PUTLONG(xdrs, (long *) &proc)) ||
-		(!AUTH_MARSHALL(h->cl_auth, xdrs)) || (!(*xargs) (xdrs, argsp))) {
-		return (RPC_CANTENCODEARGS);
+  struct clntraw_private_s *clp = clntraw_private;
+  XDR *xdrs = &clp->xdr_stream;
+  struct rpc_msg msg;
+  enum clnt_stat status;
+  struct rpc_err error;
+
+  if (clp == NULL)
+    return RPC_FAILED;
+call_again:
+  /*
+   * send request
+   */
+  xdrs->x_op = XDR_ENCODE;
+  XDR_SETPOS (xdrs, 0);
+  ((struct rpc_msg *) clp->mashl_callmsg)->rm_xid++;
+  if ((!XDR_PUTBYTES (xdrs, clp->mashl_callmsg, clp->mcnt)) ||
+      (!XDR_PUTLONG (xdrs, (long *) &proc)) ||
+      (!AUTH_MARSHALL (h->cl_auth, xdrs)) ||
+      (!(*xargs) (xdrs, argsp)))
+    {
+      return (RPC_CANTENCODEARGS);
+    }
+  (void) XDR_GETPOS (xdrs);	/* called just to cause overhead */
+
+  /*
+   * We have to call server input routine here because this is
+   * all going on in one process. Yuk.
+   */
+  svc_getreq (1);
+
+  /*
+   * get results
+   */
+  xdrs->x_op = XDR_DECODE;
+  XDR_SETPOS (xdrs, 0);
+  msg.acpted_rply.ar_verf = _null_auth;
+  msg.acpted_rply.ar_results.where = resultsp;
+  msg.acpted_rply.ar_results.proc = xresults;
+  if (!xdr_replymsg (xdrs, &msg))
+    return RPC_CANTDECODERES;
+  _seterr_reply (&msg, &error);
+  status = error.re_status;
+
+  if (status == RPC_SUCCESS)
+    {
+      if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
+	{
+	  status = RPC_AUTHERROR;
+	}
+    }				/* end successful completion */
+  else
+    {
+      if (AUTH_REFRESH (h->cl_auth))
+	goto call_again;
+    }				/* end of unsuccessful completion */
+
+  if (status == RPC_SUCCESS)
+    {
+      if (!AUTH_VALIDATE (h->cl_auth, &msg.acpted_rply.ar_verf))
+	{
+	  status = RPC_AUTHERROR;
 	}
-	(void) XDR_GETPOS(xdrs);	/* called just to cause overhead */
-
-	/*
-	 * We have to call server input routine here because this is
-	 * all going on in one process. Yuk.
-	 */
-	svc_getreq(1);
-
-	/*
-	 * get results
-	 */
-	xdrs->x_op = XDR_DECODE;
-	XDR_SETPOS(xdrs, 0);
-	msg.acpted_rply.ar_verf = _null_auth;
-	msg.acpted_rply.ar_results.where = resultsp;
-	msg.acpted_rply.ar_results.proc = xresults;
-	if (!xdr_replymsg(xdrs, &msg))
-		return (RPC_CANTDECODERES);
-	_seterr_reply(&msg, &error);
-	status = error.re_status;
-
-	if (status == RPC_SUCCESS) {
-		if (!AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
-			status = RPC_AUTHERROR;
-		}
-	} /* end successful completion */
-	else {
-		if (AUTH_REFRESH(h->cl_auth))
-			goto call_again;
-	}							/* end of unsuccessful completion */
-
-	if (status == RPC_SUCCESS) {
-		if (!AUTH_VALIDATE(h->cl_auth, &msg.acpted_rply.ar_verf)) {
-			status = RPC_AUTHERROR;
-		}
-		if (msg.acpted_rply.ar_verf.oa_base != NULL) {
-			xdrs->x_op = XDR_FREE;
-			(void) xdr_opaque_auth(xdrs, &(msg.acpted_rply.ar_verf));
-		}
+      if (msg.acpted_rply.ar_verf.oa_base != NULL)
+	{
+	  xdrs->x_op = XDR_FREE;
+	  (void) xdr_opaque_auth (xdrs, &(msg.acpted_rply.ar_verf));
 	}
+    }
 
-	return (status);
+  return status;
 }
 
-static void clntraw_geterr()
+static void
+clntraw_geterr (CLIENT *cl, struct rpc_err *err)
 {
 }
 
 
-static bool_t clntraw_freeres(cl, xdr_res, res_ptr)
-CLIENT *cl;
-xdrproc_t xdr_res;
-caddr_t res_ptr;
+static bool_t
+clntraw_freeres (cl, xdr_res, res_ptr)
+     CLIENT *cl;
+     xdrproc_t xdr_res;
+     caddr_t res_ptr;
 {
-	register struct clntraw_private *clp = clntraw_private;
-	register XDR *xdrs = &clp->xdr_stream;
-	bool_t rval;
-
-	if (clp == 0) {
-		rval = (bool_t) RPC_FAILED;
-		return (rval);
-	}
-	xdrs->x_op = XDR_FR