summaryrefslogtreecommitdiff
path: root/gnu/usr.bin/ld/shlib.c
diff options
context:
space:
mode:
authorOleg Safiullin <form@cvs.openbsd.org>2000-04-24 03:33:28 +0000
committerOleg Safiullin <form@cvs.openbsd.org>2000-04-24 03:33:28 +0000
commit48b49e3dbecf303d0aa748ddd58e2b05c7062ce5 (patch)
tree49386f86a690e410bc8543edaf0a5ac8215254a3 /gnu/usr.bin/ld/shlib.c
parent4652f5890765d50db31ba39442dd315754d49698 (diff)
Add xstrdup() - like strdup but get fatal error if memory is exhausted.
Avoid duplicates in search path. ok espie@
Diffstat (limited to 'gnu/usr.bin/ld/shlib.c')
-rw-r--r--gnu/usr.bin/ld/shlib.c16
1 files changed, 14 insertions, 2 deletions
diff --git a/gnu/usr.bin/ld/shlib.c b/gnu/usr.bin/ld/shlib.c
index 01343faf557..9c564e631d7 100644
--- a/gnu/usr.bin/ld/shlib.c
+++ b/gnu/usr.bin/ld/shlib.c
@@ -1,4 +1,4 @@
-/* $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 $ */
/*
@@ -77,10 +77,22 @@ void
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