3 /* xbt_host_t management functions */
5 /* Copyright (c) 2006 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
10 #include "xbt/sysdep.h"
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(host,xbt,"Host management");
16 /** \brief constructor */
17 xbt_host_t xbt_host_new(const char *name, int port) {
18 xbt_host_t res=xbt_new(s_xbt_host_t, 1);
19 res->name = xbt_strdup(name);
24 xbt_host_t xbt_host_copy(xbt_host_t h) {
25 return xbt_host_new(h->name,h->port);
28 /** \brief constructor. Argument should be of form '<hostname>:<port>'. */
29 xbt_host_t xbt_host_from_string(const char *hostport) {
30 xbt_host_t res=xbt_new(s_xbt_host_t, 1);
31 char *name=xbt_strdup(hostport);
32 char *port_str=strchr(name,':');
33 xbt_assert1(port_str,"argument of xbt_host_from_string should be of form <hostname>:<port>, it's '%s'", hostport);
37 res->name = xbt_strdup(name); /* it will be shorter now that we cut the port */
38 res->port = atoi(port_str);
43 /** \brief destructor */
44 void xbt_host_free(xbt_host_t host) {
46 if (host->name) free(host->name);
51 /** \brief Freeing function for dynars of xbt_host_t */
52 void xbt_host_free_voidp(void *d) {
53 xbt_host_free( (xbt_host_t) *(void**)d );