diff options
author | unknown <kaa@polly.local> | 2006-12-18 17:47:48 +0300 |
---|---|---|
committer | unknown <kaa@polly.local> | 2006-12-18 17:47:48 +0300 |
commit | e0a63c810e4ae7748ed17971f427559830b58f0f (patch) | |
tree | 8246533efc4e717695ce4f62a1df3b889baff109 /mysys | |
parent | f07393ab852963248823e137d6ba3199790401db (diff) | |
parent | 7d2d6b8bf9fca3360fcd10affdd8f2580b818259 (diff) | |
download | mariadb-git-e0a63c810e4ae7748ed17971f427559830b58f0f.tar.gz |
Merge bk-internal.mysql.com:/home/bk/mysql-5.1-maint
into polly.local:/home/kaa/src/maint/mysql-5.1-maint
Diffstat (limited to 'mysys')
-rw-r--r-- | mysys/typelib.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/mysys/typelib.c b/mysys/typelib.c index d329b687668..8906b702aa8 100644 --- a/mysys/typelib.c +++ b/mysys/typelib.c @@ -119,3 +119,54 @@ const char *get_type(TYPELIB *typelib, uint nr) return(typelib->type_names[nr]); return "?"; } + + +/* + Create a copy of a specified TYPELIB structure. + + SYNOPSIS + copy_typelib() + root pointer to a MEM_ROOT object for allocations + from pointer to a source TYPELIB structure + + RETURN + pointer to the new TYPELIB structure on successful copy, or + NULL otherwise +*/ + +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; +} |