-memcached_return memcached_server_add(memcached_st *ptr, char *hostname, unsigned int port)
-{
- memcached_host_st *host_ptr, *prev_ptr;
-
- if (!port)
- port= MEMCACHED_DEFAULT_PORT;
-
- if (!hostname)
- hostname= "localhost";
-
- if (ptr->hosts)
- {
- for (host_ptr= ptr->hosts; host_ptr; host_ptr= host_ptr->next)
- prev_ptr= host_ptr;
- host_ptr= (memcached_host_st *)malloc(sizeof(memcached_host_st));
- if (!host_ptr)
- return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
- prev_ptr->next= host_ptr;
- }
- else
- {
- ptr->hosts=
- host_ptr= (memcached_host_st *)malloc(sizeof(memcached_host_st));
- if (!host_ptr)
- return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
- }
-
- memset(host_ptr, 0, sizeof(memcached_host_st));
- host_ptr->hostname= (char *)malloc(sizeof(char) * strlen(hostname));
-
- if (!host_ptr->hostname)
- {
- free(host_ptr);
- return MEMCACHED_MEMORY_ALLOCATION_FAILURE;
- }
- memcpy(host_ptr->hostname, hostname, strlen(hostname));
- host_ptr->port= port;
-
- return MEMCACHED_SUCCESS;
-}