Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New function: xbt_host_from_string() creating an xbt_host_t from a 'toto:42042' string
authormquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 19 May 2006 09:35:23 +0000 (09:35 +0000)
committermquinson <mquinson@48e7efb5-ca39-0410-a469-dd3cf9ba447f>
Fri, 19 May 2006 09:35:23 +0000 (09:35 +0000)
git-svn-id: svn+ssh://scm.gforge.inria.fr/svn/simgrid/simgrid/trunk@2249 48e7efb5-ca39-0410-a469-dd3cf9ba447f

include/xbt/host.h
src/xbt/xbt_host.c

index f210a36..6351287 100644 (file)
@@ -21,6 +21,7 @@ typedef struct {
 } s_xbt_host_t, *xbt_host_t;
 
 xbt_host_t xbt_host_new(const char *name, int port);
+xbt_host_t xbt_host_from_string(const char *hostport);
 void xbt_host_free(xbt_host_t host);
 void xbt_host_free_voidp(void *d);
 
index c2e8e56..88eb6ea 100644 (file)
@@ -21,6 +21,21 @@ xbt_host_t xbt_host_new(const char *name, int port)  {
    return res;
 }
 
+/** \brief constructor. Argument should be of form '<hostname>:<port>'. */
+xbt_host_t xbt_host_from_string(const char *hostport)  {
+   xbt_host_t res=xbt_new(s_xbt_host_t, 1);
+   char *name=xbt_strdup(hostport);
+   char *port_str=strchr(hostport,':');
+   xbt_assert1(port_str,"argument of xbt_host_from_string should be of form <hostname>:<port>, it's '%s'", hostport);
+   *port_str='\0';
+   port_str++;
+   
+   res->name = xbt_strdup(name); /* it will be shorter now that we cut the port */
+   res->port = atoi(port_str);
+   free(name);
+   return res;
+}
+
 /** \brief destructor */
 void xbt_host_free(xbt_host_t host) {
    if (host) {