[uClibc-cvs] svn commit: trunk/uClibc/libc/inet/rpc

vapier at uclibc.org vapier at uclibc.org
Thu Aug 18 01:03:07 UTC 2005


Author: vapier
Date: 2005-08-17 19:03:06 -0600 (Wed, 17 Aug 2005)
New Revision: 11193

Log:
we have getprotobyname_r() now so use it

Modified:
   trunk/uClibc/libc/inet/rpc/clnt_generic.c


Changeset:
Modified: trunk/uClibc/libc/inet/rpc/clnt_generic.c
===================================================================
--- trunk/uClibc/libc/inet/rpc/clnt_generic.c	2005-08-18 00:59:05 UTC (rev 11192)
+++ trunk/uClibc/libc/inet/rpc/clnt_generic.c	2005-08-18 01:03:06 UTC (rev 11193)
@@ -53,7 +53,9 @@
   struct hostent hostbuf, *h;
   size_t hstbuflen;
   char *hsttmpbuf;
-  struct protoent *p;
+  struct protoent protobuf, *p;
+  size_t prtbuflen;
+  char *prttmpbuf;
   struct sockaddr_in sin;
   struct sockaddr_un sun;
   int sock;
@@ -113,14 +115,23 @@
   memset (sin.sin_zero, 0, 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;
-  }
+  prtbuflen = 1024;
+  prttmpbuf = alloca (prtbuflen);
+  while (getprotobyname_r (proto, &protobuf, prttmpbuf, prtbuflen, &p) != 0
+	 || p == NULL)
+	if (errno != ERANGE)
+      {
+	struct rpc_createerr *ce = &get_rpc_createerr ();
+	ce->cf_stat = RPC_UNKNOWNPROTO;
+	ce->cf_error.re_errno = EPFNOSUPPORT;
+	return NULL;
+      }
+    else
+      {
+	/* Enlarge the buffer.  */
+	prtbuflen *= 2;
+	prttmpbuf = alloca (prtbuflen);
+      }
 
   sock = RPC_ANYSOCK;
   switch (p->p_proto)




More information about the uClibc-cvs mailing list