diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-12-03 20:50:11 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-12-03 20:50:11 +0100 |
commit | 4cf52fc0bc3b80c0ef6c58c5db4413ebdafe661c (patch) | |
tree | 676b26b024117cf656080a011e3d17b8fb6889af /lib/relocatable.c | |
parent | 1ecbfbb92248e67b564f5b144c4671ccaa86ee2f (diff) | |
parent | 44ff3127b1e57b703c2a73a24f7ab38e4aad8ae4 (diff) |
Merge branch 'release/0.9.8-1'0.9.8-1
Diffstat (limited to 'lib/relocatable.c')
-rw-r--r-- | lib/relocatable.c | 34 |
1 files changed, 23 insertions, 11 deletions
diff --git a/lib/relocatable.c b/lib/relocatable.c index 810f19b..9c27296 100644 --- a/lib/relocatable.c +++ b/lib/relocatable.c @@ -1,5 +1,5 @@ /* Provide relocatable packages. - Copyright (C) 2003-2006, 2008-2016 Free Software Foundation, Inc. + Copyright (C) 2003-2006, 2008-2017 Free Software Foundation, Inc. Written by Bruno Haible <bruno@clisp.org>, 2003. This program is free software: you can redistribute it and/or @@ -19,10 +19,10 @@ This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU Lesser General Public License for more details. + GNU General Public License for more details. - You should have received a copy of the GNU Lesser General Public License - along with this program. If not, see <http://www.gnu.org/licenses/>. */ + You should have received a copy of the GNU General Public License + along with this program. If not, see <https://www.gnu.org/licenses/>. */ /* Tell glibc's <stdio.h> to provide a prototype for getline(). @@ -324,7 +324,7 @@ static char *shared_library_fullname; On Cygwin, it is better to use the Cygwin provided /proc interface, than to use native Windows API and cygwin_conv_to_posix_path, because it supports longer file names - (see <http://cygwin.com/ml/cygwin/2011-01/msg00410.html>). */ + (see <https://cygwin.com/ml/cygwin/2011-01/msg00410.html>). */ /* Determine the full pathname of the shared library when it is loaded. */ @@ -551,27 +551,26 @@ relocate (const char *pathname) # ifdef __KLIBC__ # undef strncmp - if (pathname && strncmp (pathname, "/@unixroot", 10) == 0 - && (pathname[10] == '\0' || pathname[10] == '/' || pathname[10] == '\\')) + if (strncmp (pathname, "/@unixroot", 10) == 0 + && (pathname[10] == '\0' || ISSLASH (pathname[10]))) { /* kLIBC itself processes /@unixroot prefix */ - return pathname; } else # endif - if (pathname && ISSLASH (pathname[0])) + if (ISSLASH (pathname[0])) { const char *unixroot = getenv ("UNIXROOT"); - if (unixroot && HAS_DEVICE (unixroot) && !unixroot[2]) + if (unixroot && HAS_DEVICE (unixroot) && unixroot[2] == '\0') { char *result = (char *) xmalloc (2 + strlen (pathname) + 1); #ifdef NO_XMALLOC if (result != NULL) #endif { - strcpy (result, unixroot); + memcpy (result, unixroot, 2); strcpy (result + 2, pathname); return result; } @@ -583,4 +582,17 @@ relocate (const char *pathname) return pathname; } +/* Returns the pathname, relocated according to the current installation + directory. + This function sets *ALLOCATEDP to the allocated memory, or to NULL if + no memory allocation occurs. So that, after you're done with the return + value, to reclaim allocated memory, you can do: free (*ALLOCATEDP). */ +const char * +relocate2 (const char *pathname, char **allocatedp) +{ + const char *result = relocate (pathname); + *allocatedp = (result != pathname ? (char *) result : NULL); + return result; +} + #endif |