+/* Add a mapping directing that the CU named FROM should have its
+ conflicting/non-duplicate types (depending on link mode) go into a container
+ named TO. Many FROMs can share a TO: in this case, the effect on conflicting
+ types is not yet defined (but in time an auto-renaming algorithm will be
+ added: ugly, but there is really no right thing one can do in this
+ situation).
+
+ We forcibly add a container named TO in every case, even though it may well
+ wind up empty, because clients that use this facility usually expect to find
+ every TO container present, even if empty, and malfunction otherwise. */
+
+int
+ctf_link_add_cu_mapping (ctf_file_t *fp, const char *from, const char *to)
+{
+ int err;
+ char *f, *t;
+
+ if (fp->ctf_link_cu_mapping == NULL)
+ fp->ctf_link_cu_mapping = ctf_dynhash_create (ctf_hash_string,
+ ctf_hash_eq_string, free,
+ free);
+ if (fp->ctf_link_cu_mapping == NULL)
+ return ctf_set_errno (fp, ENOMEM);
+
+ if (fp->ctf_link_outputs == NULL)
+ fp->ctf_link_outputs = ctf_dynhash_create (ctf_hash_string,
+ ctf_hash_eq_string, free,
+ ctf_file_close_thunk);
+
+ if (fp->ctf_link_outputs == NULL)
+ return ctf_set_errno (fp, ENOMEM);
+
+ f = strdup (from);
+ t = strdup (to);
+ if (!f || !t)
+ goto oom;
+
+ if (ctf_create_per_cu (fp, t, t) == NULL)
+ goto oom_noerrno; /* Errno is set for us. */
+
+ err = ctf_dynhash_insert (fp->ctf_link_cu_mapping, f, t);
+ if (err)
+ {
+ ctf_set_errno (fp, err);
+ goto oom_noerrno;
+ }
+
+ return 0;
+
+ oom:
+ ctf_set_errno (fp, errno);
+ oom_noerrno:
+ free (f);
+ free (t);
+ return -1;
+}
+
+/* Set a function which is called to transform the names of archive members.
+ This is useful for applying regular transformations to many names, where
+ ctf_link_add_cu_mapping applies arbitrarily irregular changes to single
+ names. The member name changer is applied at ctf_link_write time, so it
+ cannot conflate multiple CUs into one the way ctf_link_add_cu_mapping can.
+ The changer function accepts a name and should return a new
+ dynamically-allocated name, or NULL if the name should be left unchanged. */
+void
+ctf_link_set_memb_name_changer (ctf_file_t *fp,
+ ctf_link_memb_name_changer_f *changer,
+ void *arg)
+{
+ fp->ctf_link_memb_name_changer = changer;
+ fp->ctf_link_memb_name_changer_arg = arg;
+}
+