]> git.eshelyaron.com Git - emacs.git/commitdiff
Allow using "number strings" as services on non-GNU systems
authorLars Ingebrigtsen <larsi@gnus.org>
Thu, 25 Feb 2016 05:24:03 +0000 (15:54 +1030)
committerLars Ingebrigtsen <larsi@gnus.org>
Thu, 25 Feb 2016 05:24:03 +0000 (15:54 +1030)
* src/process.c (string_integer_p): New function.
(Fmake_network_process): Use it to allow connecting to
services specified as "993" even when getaddrbyname isn't
available.

src/process.c

index 8c88e62ee055573b64786d4892ed13d2301e90e8..62a26c381b9caf9fec55a2200ac8dc501f11e924 100644 (file)
@@ -3428,6 +3428,17 @@ conv_numerical_to_lisp (unsigned char *number, int length, int port)
 }
 #endif
 
+/* Return true if STRING consists only of numerical characters. */
+static bool
+string_integer_p (Lisp_Object string)
+{
+  char *s = SSDATA (string), c;
+  while ((c = *s++))
+    if (c < '0' || c > '9')
+      return false;
+  return true;
+}
+
 /* Create a network stream/datagram client/server process.  Treated
    exactly like a normal process when reading and writing.  Primary
    differences are in status display and process deletion.  A network
@@ -3852,6 +3863,10 @@ usage: (make-network-process &rest ARGS)  */)
     port = 0;
   else if (INTEGERP (service))
     port = (unsigned short) XINT (service);
+  /* Allow the service to be a string containing the port number,
+     because that's allowed if you have getaddrbyname. */
+  else if (string_integer_p (service))
+    port = strtol (SSDATA (service), NULL, 10);
   else
     {
       struct servent *svc_info;