version 1.1, 2012/02/21 22:57:48
|
version 1.1.1.3, 2021/03/17 13:38:46
|
Line 1
|
Line 1
|
/* Provide relocatable packages. |
/* Provide relocatable packages. |
Copyright (C) 2003, 2005, 2008 Free Software Foundation, Inc. | Copyright (C) 2003, 2005, 2008-2019 Free Software Foundation, Inc. |
Written by Bruno Haible <bruno@clisp.org>, 2003. |
Written by Bruno Haible <bruno@clisp.org>, 2003. |
|
|
This program is free software; you can redistribute it and/or modify it | This program is free software: you can redistribute it and/or modify |
under the terms of the GNU General Public License as published | it under the terms of the GNU General Public License as published by |
by the Free Software Foundation; either version 3, or (at your option) | the Free Software Foundation; either version 3 of the License, or |
any later version. | (at your option) any later version. |
|
|
This program is distributed in the hope that it will be useful, |
This program is distributed in the hope that it will be useful, |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
Library General Public License for more details. | GNU General Public License for more details. |
|
|
You should have received a copy of the GNU General Public | You should have received a copy of the GNU General Public License |
License along with this program; if not, write to the Free Software | along with this program. If not, see <https://www.gnu.org/licenses/>. */ |
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, | |
USA. */ | |
|
|
#ifndef _RELOCATABLE_H |
#ifndef _RELOCATABLE_H |
#define _RELOCATABLE_H |
#define _RELOCATABLE_H |
Line 46 extern "C" {
|
Line 44 extern "C" {
|
instead of "/"). */ |
instead of "/"). */ |
extern RELOCATABLE_DLL_EXPORTED void |
extern RELOCATABLE_DLL_EXPORTED void |
set_relocation_prefix (const char *orig_prefix, |
set_relocation_prefix (const char *orig_prefix, |
const char *curr_prefix); | const char *curr_prefix); |
|
|
/* Returns the pathname, relocated according to the current installation |
/* Returns the pathname, relocated according to the current installation |
directory. |
directory. |
Line 54 extern RELOCATABLE_DLL_EXPORTED void
|
Line 52 extern RELOCATABLE_DLL_EXPORTED void
|
string that you can free with free() after casting it to 'char *'. */ |
string that you can free with free() after casting it to 'char *'. */ |
extern const char * relocate (const char *pathname); |
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 |
/* Memory management: relocate() potentially allocates memory, because it has |
to construct a fresh pathname. If this is a problem because your program |
to construct a fresh pathname. If this is a problem because your program |
calls relocate() frequently, think about caching the result. Or free the | calls relocate() frequently or because you want to fix all potential memory |
return value if it was different from the argument pathname. */ | 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: |
/* Convenience function: |
Computes the current installation prefix, based on the original |
Computes the current installation prefix, based on the original |
Line 65 extern const char * relocate (const char *pathname);
|
Line 82 extern const char * relocate (const char *pathname);
|
file, and the current pathname of this file. |
file, and the current pathname of this file. |
Returns it, freshly allocated. Returns NULL upon failure. */ |
Returns it, freshly allocated. Returns NULL upon failure. */ |
extern char * compute_curr_prefix (const char *orig_installprefix, |
extern char * compute_curr_prefix (const char *orig_installprefix, |
const char *orig_installdir, | const char *orig_installdir, |
const char *curr_pathname); | const char *curr_pathname); |
|
|
#else |
#else |
|
|
/* By default, we use the hardwired pathnames. */ |
/* By default, we use the hardwired pathnames. */ |
#define relocate(pathname) (pathname) |
#define relocate(pathname) (pathname) |
|
#define relocate2(pathname,allocatedp) (*(allocatedp) = NULL, (pathname)) |
|
|
#endif |
#endif |
|
|