Enchant Generic spell checking library

relocatable.h
1 /* Provide relocatable packages.
2 Copyright (C) 2003, 2005, 2008-2023 Free Software Foundation, Inc.
3 Written by Bruno Haible <bruno@clisp.org>, 2003.
4
5 This file is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as
7 published by the Free Software Foundation; either version 2.1 of the
8 License, or (at your option) any later version.
9
10 This file is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program. If not, see <https://www.gnu.org/licenses/>. */
17
18 #ifndef _RELOCATABLE_H
19 #define _RELOCATABLE_H
20
21 /* This file uses _GL_ATTRIBUTE_MALLOC, HAVE_VISIBILITY. */
22 #if !_GL_CONFIG_H_INCLUDED
23 #error "Please include config.h first."
24 #endif
25
26 #include <stdlib.h>
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31
32
33 /* This can be enabled through the configure --enable-relocatable option. */
34 #if ENABLE_RELOCATABLE
35
36 /* When building a DLL, we must export some functions. Note that because
37 this is a private .h file, we don't need to use __declspec(dllimport)
38 in any case. */
39 #if HAVE_VISIBILITY && BUILDING_DLL
40 # define RELOCATABLE_DLL_EXPORTED __attribute__((__visibility__("default")))
41 #elif defined _MSC_VER && BUILDING_DLL
42 # define RELOCATABLE_DLL_EXPORTED __declspec(dllexport)
43 #else
44 # define RELOCATABLE_DLL_EXPORTED
45 #endif
46
47 /* Sets the original and the current installation prefix of the package.
48 Relocation simply replaces a pathname starting with the original prefix
49 by the corresponding pathname with the current prefix instead. Both
50 prefixes should be directory names without trailing slash (i.e. use ""
51 instead of "/"). */
52 extern RELOCATABLE_DLL_EXPORTED void
53 set_relocation_prefix (const char *orig_prefix,
54 const char *curr_prefix);
55
56 /* Returns the pathname, relocated according to the current installation
57 directory.
58 The returned string is either PATHNAME unmodified or a freshly allocated
59 string that you can free with free() after casting it to 'char *'. */
60 extern const char * relocate (const char *pathname);
61
62 /* Returns the pathname, relocated according to the current installation
63 directory.
64 This function sets *ALLOCATEDP to the allocated memory, or to NULL if
65 no memory allocation occurs. So that, after you're done with the return
66 value, to reclaim allocated memory, you can do: free (*ALLOCATEDP). */
67 extern const char * relocate2 (const char *pathname, char **allocatedp);
68
69 /* Memory management: relocate() potentially allocates memory, because it has
70 to construct a fresh pathname. If this is a problem because your program
71 calls relocate() frequently or because you want to fix all potential memory
72 leaks anyway, you have three options:
73 1) Use this idiom:
74 const char *pathname = ...;
75 const char *rel_pathname = relocate (pathname);
76 ...
77 if (rel_pathname != pathname)
78 free ((char *) rel_pathname);
79 2) Use this idiom:
80 char *allocated;
81 const char *rel_pathname = relocate2 (..., &allocated);
82 ...
83 free (allocated);
84 3) Think about caching the result. */
85
86 /* Convenience function:
87 Computes the current installation prefix, based on the original
88 installation prefix, the original installation directory of a particular
89 file, and the current pathname of this file.
90 Returns it, freshly allocated. Returns NULL upon failure. */
91 extern char * compute_curr_prefix (const char *orig_installprefix,
92 const char *orig_installdir,
93 const char *curr_pathname)
94 _GL_ATTRIBUTE_MALLOC _GL_ATTRIBUTE_DEALLOC_FREE;
95
96 #else
97
98 /* By default, we use the hardwired pathnames. */
99 #define relocate(pathname) (pathname)
100 #define relocate2(pathname,allocatedp) (*(allocatedp) = NULL, (pathname))
101
102 #endif
103
104
105 #ifdef __cplusplus
106 }
107 #endif
108
109 #endif /* _RELOCATABLE_H */