]> rtime.felk.cvut.cz Git - frescor/frsh.git/commitdiff
Added fres_container_copy()
authorMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 13 May 2009 00:14:32 +0000 (02:14 +0200)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Wed, 13 May 2009 06:44:47 +0000 (08:44 +0200)
fres/contract/fres_container.c
fres/contract/fres_container.h

index 8fa60b9dbf76750fb6d95623b5098126853fb160..a067c4134e16936020629232512e59138c847fbd 100644 (file)
@@ -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; type<FRES_NUM_BLOCKS; type++) {
+               const struct fres_block *sb = &src->blocks[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;
+}
index 924ff57b8e9360313e499fa4ffa7c08e32c53d1e..dabc877f43eeb8866f98012db786b46d975bbfd6 100644 (file)
@@ -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