summaryrefslogtreecommitdiff
path: root/libstore/clone.c
diff options
context:
space:
mode:
authorMiles Bader <miles@gnu.org>1996-04-02 22:27:19 +0000
committerMiles Bader <miles@gnu.org>1996-04-02 22:27:19 +0000
commit32145142fba4c431048ae49bc81ac990f8693049 (patch)
tree59e306a7bbc3ad9ce50d173416d0edc11ae0a171 /libstore/clone.c
parent62338750ce59734a803a6986c7e800907ae4186a (diff)
Initial revision
Diffstat (limited to 'libstore/clone.c')
-rw-r--r--libstore/clone.c71
1 files changed, 71 insertions, 0 deletions
diff --git a/libstore/clone.c b/libstore/clone.c
new file mode 100644
index 00000000..a1817982
--- /dev/null
+++ b/libstore/clone.c
@@ -0,0 +1,71 @@
+/* Store cloning
+
+ Copyright (C) 1996 Free Software Foundation, Inc.
+
+ Written by Miles Bader <miles@gnu.ai.mit.edu>
+
+ This file is part of the GNU Hurd.
+
+ The GNU Hurd is free software; you can redistribute it and/or
+ modify it under the terms of the GNU General Public License as
+ published by the Free Software Foundation; either version 2, or (at
+ your option) any later version.
+
+ The GNU Hurd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+#include <string.h>
+
+#include "store.h"
+
+/* Return in TO a copy of FROM. */
+error_t
+store_clone (struct store *from, struct store **to)
+{
+ struct store *c =
+ _make_store (from->class, from->meths, from->port, from->block_size,
+ from->runs, from->runs_len, from->end);
+
+ if (! c)
+ return ENOMEM;
+
+ c->flags = from->flags;
+
+ if (from->misc_len)
+ {
+ c->misc = malloc (from->misc_len);
+ if (! c->misc)
+ err = ENOMEM;
+ }
+
+ if (!err && c->port != MACH_PORT_NULL)
+ {
+ err = mach_port_mod_refs (mach_task_self (),
+ c->port, MACH_PORT_RIGHT_SEND, 1);
+ if (err)
+ c->port = MACH_PORT_NULL; /* Don't deallocate it. */
+ }
+ if (!err && from->source != MACH_PORT_NULL)
+ {
+ err = mach_port_mod_refs (mach_task_self (),
+ from->source, MACH_PORT_RIGHT_SEND, 1);
+ if (! err)
+ to->source = from->source;
+ }
+
+ if (!err && from->meths->clone)
+ err = (*from->meths->clone)(from, c);
+
+ if (err)
+ store_free (c);
+ else
+ *to = c;
+
+ return err;
+}