+/* Helper routine to check for identity of string pointers,
+ which might be NULL. */
+
+static int
+are_names_equal (const char *s1, const char *s2)
+{
+ if (!s1 && !s2)
+ return 0;
+ if (!s1 || !s2)
+ return (!s1 ? -1 : 1);
+ return strcmp (s1, s2);
+}
+
+static int
+cmp_export_elem (const def_file_export *e, const char *ex_name,
+ const char *in_name, const char *its_name,
+ int ord)
+{
+ int r;
+
+ if ((r = are_names_equal (ex_name, e->name)) != 0)
+ return r;
+ if ((r = are_names_equal (in_name, e->internal_name)) != 0)
+ return r;
+ if ((r = are_names_equal (its_name, e->its_name)) != 0)
+ return r;
+ return (ord - e->ordinal);
+}
+
+/* Search the position of the identical element, or returns the position
+ of the next higher element. If last valid element is smaller, then MAX
+ is returned. */
+
+static int
+find_export_in_list (def_file_export *b, int max,
+ const char *ex_name, const char *in_name,
+ const char *its_name, int ord, int *is_ident)
+{
+ int e, l, r, p;
+
+ *is_ident = 0;
+ if (!max)
+ return 0;
+ if ((e = cmp_export_elem (b, ex_name, in_name, its_name, ord)) <= 0)
+ {
+ if (!e)
+ *is_ident = 1;
+ return 0;
+ }
+ if (max == 1)
+ return 1;
+ if ((e = cmp_export_elem (b + (max - 1), ex_name, in_name, its_name, ord)) > 0)
+ return max;
+ else if (!e || max == 2)
+ {
+ if (!e)
+ *is_ident = 1;
+ return max - 1;
+ }
+ l = 0; r = max - 1;
+ while (l < r)
+ {
+ p = (l + r) / 2;
+ e = cmp_export_elem (b + p, ex_name, in_name, its_name, ord);
+ if (!e)
+ {
+ *is_ident = 1;
+ return p;
+ }
+ else if (e < 0)
+ r = p - 1;
+ else if (e > 0)
+ l = p + 1;
+ }
+ if ((e = cmp_export_elem (b + l, ex_name, in_name, its_name, ord)) > 0)
+ ++l;
+ else if (!e)
+ *is_ident = 1;
+ return l;
+}
+