annotate lib/relocatable.h @ 14379:2330aac2ae54

maint: adjust cpp indentation to reflect nesting depth I.e., in a block of code that begins with an unnested "#if", put one space between the "#" in column 1 and following token. For example, -#include <sys/vfs.h> +# include <sys/vfs.h> Do this only in .c files that are part of a module I maintain. * lib/linkat.c: Filter through cppi. * lib/nanosleep.c: Likewise. * lib/openat.c: Likewise. * lib/openat-die.c: Likewise. * lib/dup3.c: Likewise. * lib/fchownat.c: Likewise. * lib/flock.c: Likewise. * lib/fsync.c: Likewise. * lib/fts.c: Likewise. * lib/getpass.c: Likewise. * lib/gettimeofday.c: Likewise. * lib/userspec.c: Likewise. * Makefile (sc_cpp_indent_check): New rule, to check this.
author Jim Meyering <meyering@redhat.com>
date Sun, 20 Feb 2011 23:02:43 +0100
parents 97fc9a21a8fb
children dd10bbc31f53
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8265
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Provide relocatable packages.
14079
97fc9a21a8fb maint: update almost all copyright ranges to include 2011
Jim Meyering <meyering@redhat.com>
parents: 12559
diff changeset
2 Copyright (C) 2003, 2005, 2008-2011 Free Software Foundation, Inc.
8265
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2003.
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify it
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 under the terms of the GNU Library General Public License as published
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 by the Free Software Foundation; either version 2, or (at your option)
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8 any later version.
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13 Library General Public License for more details.
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16 License along with this program; if not, write to the Free Software
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18 USA. */
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 #ifndef _RELOCATABLE_H
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 #define _RELOCATABLE_H
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 #ifdef __cplusplus
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 extern "C" {
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 #endif
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 /* This can be enabled through the configure --enable-relocatable option. */
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 #if ENABLE_RELOCATABLE
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 /* When building a DLL, we must export some functions. Note that because
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 this is a private .h file, we don't need to use __declspec(dllimport)
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 in any case. */
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 #if HAVE_VISIBILITY && BUILDING_DLL
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 # define RELOCATABLE_DLL_EXPORTED __attribute__((__visibility__("default")))
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 #elif defined _MSC_VER && BUILDING_DLL
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 # define RELOCATABLE_DLL_EXPORTED __declspec(dllexport)
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 #else
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 # define RELOCATABLE_DLL_EXPORTED
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 #endif
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42 /* Sets the original and the current installation prefix of the package.
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 Relocation simply replaces a pathname starting with the original prefix
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 by the corresponding pathname with the current prefix instead. Both
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 prefixes should be directory names without trailing slash (i.e. use ""
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 instead of "/"). */
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 extern RELOCATABLE_DLL_EXPORTED void
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 set_relocation_prefix (const char *orig_prefix,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9602
diff changeset
49 const char *curr_prefix);
8265
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 /* Returns the pathname, relocated according to the current installation
9599
895b5215b578 Make it possible to avoid all memory leaks when calling relocate().
Bruno Haible <bruno@clisp.org>
parents: 9576
diff changeset
52 directory.
895b5215b578 Make it possible to avoid all memory leaks when calling relocate().
Bruno Haible <bruno@clisp.org>
parents: 9576
diff changeset
53 The returned string is either PATHNAME unmodified or a freshly allocated
895b5215b578 Make it possible to avoid all memory leaks when calling relocate().
Bruno Haible <bruno@clisp.org>
parents: 9576
diff changeset
54 string that you can free with free() after casting it to 'char *'. */
8265
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
55 extern const char * relocate (const char *pathname);
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
56
9602
7a4db0f92545 Fix a comment.
Eric Blake <ebb9@byu.net>
parents: 9599
diff changeset
57 /* Memory management: relocate() potentially allocates memory, because it has
7a4db0f92545 Fix a comment.
Eric Blake <ebb9@byu.net>
parents: 9599
diff changeset
58 to construct a fresh pathname. If this is a problem because your program
7a4db0f92545 Fix a comment.
Eric Blake <ebb9@byu.net>
parents: 9599
diff changeset
59 calls relocate() frequently, think about caching the result. Or free the
9599
895b5215b578 Make it possible to avoid all memory leaks when calling relocate().
Bruno Haible <bruno@clisp.org>
parents: 9576
diff changeset
60 return value if it was different from the argument pathname. */
8265
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
61
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
62 /* Convenience function:
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
63 Computes the current installation prefix, based on the original
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
64 installation prefix, the original installation directory of a particular
9576
8cae100b8cd1 Improve memory cleanup in 'relocatable' module.
Bruno Haible <bruno@clisp.org>
parents: 8265
diff changeset
65 file, and the current pathname of this file.
8cae100b8cd1 Improve memory cleanup in 'relocatable' module.
Bruno Haible <bruno@clisp.org>
parents: 8265
diff changeset
66 Returns it, freshly allocated. Returns NULL upon failure. */
8cae100b8cd1 Improve memory cleanup in 'relocatable' module.
Bruno Haible <bruno@clisp.org>
parents: 8265
diff changeset
67 extern char * compute_curr_prefix (const char *orig_installprefix,
12421
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9602
diff changeset
68 const char *orig_installdir,
e8d2c6fc33ad Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents: 9602
diff changeset
69 const char *curr_pathname);
8265
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
70
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
71 #else
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
72
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
73 /* By default, we use the hardwired pathnames. */
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
74 #define relocate(pathname) (pathname)
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
75
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
76 #endif
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
77
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
78
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
79 #ifdef __cplusplus
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
80 }
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
81 #endif
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
82
20006894dae4 Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
83 #endif /* _RELOCATABLE_H */