X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=sidebyside;f=lib%2Frelocatable.c;h=09ff8c9efaa45d2df9b096837c8cf1fceb17a19f;hb=8de32ec2916ffe14843acf4a53a465a5d413577f;hp=e814a0e4ebd620d09e44f6df05425fdcb507bc48;hpb=1146b210ba48607a5a29ea516a5cda3d5afa6542;p=gnulib.git diff --git a/lib/relocatable.c b/lib/relocatable.c index e814a0e4e..09ff8c9ef 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];