X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/51a05a5d56fdeed675ae02e0ecbb6fbae9cf9a37..f21b4400e959778d4a1200e1b0c1a942715bb95d:/src/xbt/xbt_host.c diff --git a/src/xbt/xbt_host.c b/src/xbt/xbt_host.c index c66892617b..d1b3930e66 100644 --- a/src/xbt/xbt_host.c +++ b/src/xbt/xbt_host.c @@ -14,13 +14,32 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host,xbt,"Host management"); /** \brief constructor */ -xbt_host_t xbt_host_new(char *name, int port) { +xbt_host_t xbt_host_new(const char *name, int port) { xbt_host_t res=xbt_new(s_xbt_host_t, 1); - res->name = name; + res->name = xbt_strdup(name); res->port = port; return res; } +xbt_host_t xbt_host_copy(xbt_host_t h) { + return xbt_host_new(h->name,h->port); +} + +/** \brief constructor. Argument should be of form ':'. */ +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(name,':'); + xbt_assert1(port_str,"argument of xbt_host_from_string should be of form :, 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) {