diff options
author | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-12-02 10:30:25 +0100 |
---|---|---|
committer | Jörg Frings-Fürst <debian@jff-webhosting.net> | 2017-12-02 10:30:25 +0100 |
commit | 44a3eaeba04ef78835ca741592c376428ada5f71 (patch) | |
tree | 29cc935fd475678dcbe38972bfa77fdc68ffb10d /lib/relocatable.h | |
parent | 6b73edd95d603e27d55d4905134ac1327d426534 (diff) |
New upstream version 0.9.8upstream/0.9.8
Diffstat (limited to 'lib/relocatable.h')
-rw-r--r-- | lib/relocatable.h | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/lib/relocatable.h b/lib/relocatable.h index ebe60dfd..ba75d337 100644 --- a/lib/relocatable.h +++ b/lib/relocatable.h @@ -1,5 +1,5 @@ /* Provide relocatable packages. - Copyright (C) 2003, 2005, 2008-2016 Free Software Foundation, Inc. + Copyright (C) 2003, 2005, 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/>. */ #ifndef _RELOCATABLE_H #define _RELOCATABLE_H @@ -61,10 +61,29 @@ extern RELOCATABLE_DLL_EXPORTED void string that you can free with free() after casting it to 'char *'. */ extern const char * relocate (const char *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). */ +extern const char * relocate2 (const char *pathname, char **allocatedp); + /* Memory management: relocate() potentially allocates 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. Or free the - return value if it was different from the argument pathname. */ + calls relocate() frequently or because you want to fix all potential memory + leaks anyway, you have three options: + 1) Use this idiom: + const char *pathname = ...; + const char *rel_pathname = relocate (pathname); + ... + if (rel_pathname != pathname) + free ((char *) rel_pathname); + 2) Use this idiom: + char *allocated; + const char *rel_pathname = relocate2 (..., &allocated); + ... + free (allocated); + 3) Think about caching the result. */ /* Convenience function: Computes the current installation prefix, based on the original @@ -79,6 +98,7 @@ extern char * compute_curr_prefix (const char *orig_installprefix, /* By default, we use the hardwired pathnames. */ #define relocate(pathname) (pathname) +#define relocate2(pathname,allocatedp) (*(allocatedp) = NULL, (pathname)) #endif |