From: Michal Sojka Date: Wed, 13 May 2009 00:14:32 +0000 (+0200) Subject: Added fres_container_copy() X-Git-Url: https://rtime.felk.cvut.cz/gitweb/frescor/frsh.git/commitdiff_plain/5d0a7a1cff3e9f1a2f55a6d6330de4a2d17ab291 Added fres_container_copy() --- diff --git a/fres/contract/fres_container.c b/fres/contract/fres_container.c index 8fa60b9..a067c41 100644 --- a/fres/contract/fres_container.c +++ b/fres/contract/fres_container.c @@ -728,3 +728,33 @@ int fres_container_merge(struct fres_container *dest, } return 0; } + +/** + * Copy blocks from a container into another one. Blocks present in + * both @a src and @a dest are replaced in @a dest. + * + * @param dest Destination of copy operation + * @param src Source of copy operation + * + * @return Zero on success, non-zero error core on error. + */ +int fres_container_copy(struct fres_container *dest, + const struct fres_container *src) +{ + enum fres_block_type type; + int ret; + + for (type=0; typeblocks[type]; + struct fres_block *db = &dest->blocks[type]; + + if (sb->state != FRES_BLOCK_EMPTY) { + fres_container_del_block(dest, type); + ret = fres_block_duplicate(db, sb, type); + if (ret) { + return ret; + } + } + } + return 0; +} diff --git a/fres/contract/fres_container.h b/fres/contract/fres_container.h index 924ff57..dabc877 100644 --- a/fres/contract/fres_container.h +++ b/fres/contract/fres_container.h @@ -187,6 +187,9 @@ fres_container_get_num_blocks(const struct fres_container *c); int fres_container_merge(struct fres_container *dest, const struct fres_container *src); +int fres_container_copy(struct fres_container *dest, + const struct fres_container *src); + #ifdef __cplusplus } /* extern "C"*/ #endif