static int add_directory(MEM_ROOT *alloc, const char *dir, const char **dirs) { char buf[FN_REFLEN]; size_t len; char *p; my_bool err __attribute__((unused)); len= normalize_dirname(buf, dir); if (!(p= strmake_root(alloc, buf, len))) return 1; /* Failure */ /* Should never fail if DEFAULT_DIRS_SIZE is correct size */ err= array_append_string_unique(p, dirs, DEFAULT_DIRS_SIZE); DBUG_ASSERT(err == FALSE); return 0; }
TYPELIB *copy_typelib(MEM_ROOT *root, TYPELIB *from) { TYPELIB *to; uint i; if (!from) return NULL; if (!(to= (TYPELIB*) alloc_root(root, sizeof(TYPELIB)))) return NULL; if (!(to->type_names= (const char **) alloc_root(root, (sizeof(char *) + sizeof(int)) * (from->count + 1)))) return NULL; to->type_lengths= (unsigned int *)(to->type_names + from->count + 1); to->count= from->count; if (from->name) { if (!(to->name= strdup_root(root, from->name))) return NULL; } else to->name= NULL; for (i= 0; i < from->count; i++) { if (!(to->type_names[i]= strmake_root(root, from->type_names[i], from->type_lengths[i]))) return NULL; to->type_lengths[i]= from->type_lengths[i]; } to->type_names[to->count]= NULL; to->type_lengths[to->count]= 0; return to; }
static FOREIGN_SERVER *clone_server(MEM_ROOT *mem, const FOREIGN_SERVER *server, FOREIGN_SERVER *buffer) { DBUG_ENTER("sql_server.cc:clone_server"); if (!buffer) buffer= (FOREIGN_SERVER *) alloc_root(mem, sizeof(FOREIGN_SERVER)); buffer->server_name= strmake_root(mem, server->server_name, server->server_name_length); buffer->port= server->port; buffer->server_name_length= server->server_name_length; /* TODO: We need to examine which of these can really be NULL */ buffer->db= server->db ? strdup_root(mem, server->db) : NULL; buffer->scheme= server->scheme ? strdup_root(mem, server->scheme) : NULL; buffer->username= server->username? strdup_root(mem, server->username): NULL; buffer->password= server->password? strdup_root(mem, server->password): NULL; buffer->socket= server->socket ? strdup_root(mem, server->socket) : NULL; buffer->owner= server->owner ? strdup_root(mem, server->owner) : NULL; buffer->host= server->host ? strdup_root(mem, server->host) : NULL; DBUG_RETURN(buffer); }