Avoid duplicates in search path.
ok espie@
-/* * $OpenBSD: etc.c,v 1.2 1998/03/26 19:46:18 niklas Exp $*/
+/* * $OpenBSD: etc.c,v 1.3 2000/04/24 03:33:27 form Exp $*/
/*
*/
#include <stdlib.h>
#include <string.h>
+/*
+ * Like strdup but get fatal error if memory is exhausted.
+ */
+char *
+xstrdup(s)
+ char *s;
+{
+ char *result = strdup(s);
+
+ if (!result)
+ errx(1, "virtual memory exhausted");
+
+ return result;
+}
+
/*
* Like malloc but get fatal error if memory is exhausted.
*/
-/* $OpenBSD: ld.h,v 1.4 1999/05/10 16:18:33 espie Exp $ */
+/* $OpenBSD: ld.h,v 1.5 2000/04/24 03:33:27 form Exp $ */
/*-
* This code is derived from software copyrighted by the Free Software
int do_warnings __P((FILE *));
/* In etc.c: */
+char *xstrdup __P((char *));
void *xmalloc __P((size_t));
void *xrealloc __P((void *, size_t));
char *concat __P((const char *, const char *, const char *));
-/* $OpenBSD: shlib.c,v 1.8 2000/01/16 14:31:26 espie Exp $ */
+/* $OpenBSD: shlib.c,v 1.9 2000/04/24 03:33:27 form Exp $ */
/* $NetBSD: shlib.c,v 1.13 1998/04/04 01:00:29 fvdl Exp $ */
/*
add_search_dir(name)
char *name;
{
+ int i, len;
+
+ len = strlen(name);
+
+ while (len > 1 && name[len - 1] == '/')
+ --len;
+
+ for (i = 0; i < n_search_dirs; i++)
+ if (strlen(search_dirs[i]) == len &&
+ !strncmp(search_dirs[i], name, len))
+ return;
n_search_dirs++;
search_dirs = (char **)
xrealloc(search_dirs, n_search_dirs * sizeof search_dirs[0]);
- search_dirs[n_search_dirs - 1] = strdup(name);
+ search_dirs[n_search_dirs - 1] = xmalloc(++len);
+ (void)strlcpy(search_dirs[n_search_dirs - 1], name, len);
}
void