summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/relocatable.c20
-rw-r--r--lib/relocatable.h7
2 files changed, 21 insertions, 6 deletions
diff --git a/lib/relocatable.c b/lib/relocatable.c
index e814a0e4eb..09ff8c9efa 100644
--- a/lib/relocatable.c
+++ b/lib/relocatable.c
@@ -409,7 +409,9 @@ get_shared_library_fullname ()
#endif /* PIC */
/* Returns the pathname, relocated according to the current installation
- directory. */
+ directory.
+ The returned string is either PATHNAME unmodified or a freshly allocated
+ string that you can free with free() after casting it to 'char *'. */
const char *
relocate (const char *pathname)
{
@@ -455,9 +457,19 @@ relocate (const char *pathname)
&& strncmp (pathname, orig_prefix, orig_prefix_len) == 0)
{
if (pathname[orig_prefix_len] == '\0')
- /* pathname equals orig_prefix. */
- return curr_prefix;
- if (ISSLASH (pathname[orig_prefix_len]))
+ {
+ /* pathname equals orig_prefix. */
+ char *result = (char *) xmalloc (strlen (curr_prefix) + 1);
+
+#ifdef NO_XMALLOC
+ if (result != NULL)
+#endif
+ {
+ strcpy (result, curr_prefix);
+ return result;
+ }
+ }
+ else if (ISSLASH (pathname[orig_prefix_len]))
{
/* pathname starts with orig_prefix. */
const char *pathname_tail = &pathname[orig_prefix_len];
diff --git a/lib/relocatable.h b/lib/relocatable.h
index 5970be7a27..8f1e2aa1b6 100644
--- a/lib/relocatable.h
+++ b/lib/relocatable.h
@@ -49,12 +49,15 @@ extern RELOCATABLE_DLL_EXPORTED void
const char *curr_prefix);
/* Returns the pathname, relocated according to the current installation
- directory. */
+ directory.
+ The returned string is either PATHNAME unmodified or a freshly allocated
+ string that you can free with free() after casting it to 'char *'. */
extern const char * relocate (const char *pathname);
/* Memory management: relocate() leaks memory, because it has to construct
a fresh pathname. If this is a problem because your program calls
- relocate() frequently, think about caching the result. */
+ relocate() frequently, think about caching the result. Or free the
+ return value if it was different from the argument pathname. */
/* Convenience function:
Computes the current installation prefix, based on the original