Mercurial > gnulib
annotate lib/relocwrapper.c @ 17324:b1b7de2c4a71
careadlinkat: stop exporting careadlinkatcwd
Only Emacs used it directly, and Emacs no longer needs it.
* NEWS: Document this simplification.
* lib/areadlink.c (careadlinkatcwd): Move here from careadlinkat.c,
and make it static. Include <stdlib.h>, for abort, and unistd.h,
for readlink.
* lib/careadlinkat.c (careadlinkatcwd): Move to areadlink.c.
Don't include stdlib.h; no longer needed.
* lib/careadlinkat.h (careadlinkatcwd): Remove decl.
* lib/relocwrapper.c: Adjust comment to match new dependencies.
* modules/areadlink (Depends-on): Add readlink.
(Maintainer): Add self.
* modules/careadlinkat (Depends-on): Remove readlink.
author | Paul Eggert <eggert@cs.ucla.edu> |
---|---|
date | Fri, 08 Feb 2013 15:12:36 -0800 |
parents | e542fd46ad6f |
children | 344018b6e5d7 |
rev | line source |
---|---|
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
1 /* Relocating wrapper program. |
17249
e542fd46ad6f
maint: update all copyright year number ranges
Eric Blake <eblake@redhat.com>
parents:
16201
diff
changeset
|
2 Copyright (C) 2003, 2005-2007, 2009-2013 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 |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9238
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify |
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
6 it under the terms of the GNU General Public License as published by |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9238
diff
changeset
|
7 the Free Software Foundation; either version 3 of the License, or |
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9238
diff
changeset
|
8 (at your option) any later version. |
8265
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 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
13 GNU 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 General Public License |
9309
bbbbbf4cd1c5
Change copyright notice from GPLv2+ to GPLv3+.
Bruno Haible <bruno@clisp.org>
parents:
9238
diff
changeset
|
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
17 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
18 /* Dependencies: |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
19 relocwrapper |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
20 -> progname |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
21 -> progreloc |
9547
c3d038b0b4d3
Fix link error in relocatability wrappers, due to xalloc_die().
Bruno Haible <bruno@clisp.org>
parents:
9545
diff
changeset
|
22 -> areadlink |
14553
baaebd37cd28
relocatable-prog-wrapper: Update after module 'areadlink' changed.
Bruno Haible <bruno@clisp.org>
parents:
14545
diff
changeset
|
23 -> careadlinkat |
baaebd37cd28
relocatable-prog-wrapper: Update after module 'areadlink' changed.
Bruno Haible <bruno@clisp.org>
parents:
14545
diff
changeset
|
24 -> allocator |
17324
b1b7de2c4a71
careadlinkat: stop exporting careadlinkatcwd
Paul Eggert <eggert@cs.ucla.edu>
parents:
17249
diff
changeset
|
25 -> readlink |
8308
964437da2190
Depend on canonicalize-lgpl, not canonicalize.
Bruno Haible <bruno@clisp.org>
parents:
8272
diff
changeset
|
26 -> canonicalize-lgpl |
8948
a162347a0232
Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents:
8308
diff
changeset
|
27 -> malloca |
9547
c3d038b0b4d3
Fix link error in relocatability wrappers, due to xalloc_die().
Bruno Haible <bruno@clisp.org>
parents:
9545
diff
changeset
|
28 -> readlink |
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
29 -> relocatable |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
30 -> setenv |
8948
a162347a0232
Update after allocsa -> malloca renaming.
Bruno Haible <bruno@clisp.org>
parents:
8308
diff
changeset
|
31 -> malloca |
8272
fd48e35f4e5e
New modules relocatable, relocatable-lib, relocatable-script.
Bruno Haible <bruno@clisp.org>
parents:
8265
diff
changeset
|
32 -> c-ctype |
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
33 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
34 Macros that need to be set while compiling this file: |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
35 - ENABLE_RELOCATABLE 1 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
36 - INSTALLPREFIX the base installation directory |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
37 - INSTALLDIR the directory into which this program is installed |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
38 - LIBPATHVAR the platform dependent runtime library path variable |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
39 - LIBDIRS a comma-terminated list of strings representing the list of |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
40 directories that contain the libraries at installation time |
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 We don't want to internationalize this wrapper because then it would |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
43 depend on libintl and therefore need relocation itself. So use only |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
44 libc functions, no gettext(), no error(), no xmalloc(), no xsetenv(). |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
45 */ |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
46 |
14545
4fafdd043aff
* lib/relocwrapper.c (_GL_USE_STDLIB_ALLOC, malloc): Likewise.
Paul Eggert <eggert@cs.ucla.edu>
parents:
14079
diff
changeset
|
47 #define _GL_USE_STDLIB_ALLOC 1 |
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
48 #include <config.h> |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
49 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
50 #include <stdio.h> |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
51 #include <stdlib.h> |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
52 #include <string.h> |
8272
fd48e35f4e5e
New modules relocatable, relocatable-lib, relocatable-script.
Bruno Haible <bruno@clisp.org>
parents:
8265
diff
changeset
|
53 #include <unistd.h> |
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
54 #include <errno.h> |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
55 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
56 #include "progname.h" |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
57 #include "relocatable.h" |
8272
fd48e35f4e5e
New modules relocatable, relocatable-lib, relocatable-script.
Bruno Haible <bruno@clisp.org>
parents:
8265
diff
changeset
|
58 #include "c-ctype.h" |
13788
6f8ee3f6161c
rewrite int foo[2*X-1] to verify(X) or to int foo[X?1:-1]
Paul Eggert <eggert@cs.ucla.edu>
parents:
13397
diff
changeset
|
59 #include "verify.h" |
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
60 |
13397
758ef73803db
Avoid relocwrapper link errors due to gnulib replacement functions.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
61 /* Use the system functions, not the gnulib overrides in this file. */ |
758ef73803db
Avoid relocwrapper link errors due to gnulib replacement functions.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
62 #undef fprintf |
758ef73803db
Avoid relocwrapper link errors due to gnulib replacement functions.
Bruno Haible <bruno@clisp.org>
parents:
12559
diff
changeset
|
63 |
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
64 /* Return a copy of the filename, with an extra ".bin" at the end. |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
65 More generally, it replaces "${EXEEXT}" at the end with ".bin${EXEEXT}". */ |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
66 static char * |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
67 add_dotbin (const char *filename) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
68 { |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
69 size_t filename_len = strlen (filename); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
70 char *result = (char *) malloc (filename_len + 4 + 1); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
71 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
72 if (result != NULL) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
73 { |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
74 if (sizeof (EXEEXT) > sizeof ("")) |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
75 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
76 /* EXEEXT handling. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
77 const size_t exeext_len = sizeof (EXEEXT) - sizeof (""); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
78 static const char exeext[] = EXEEXT; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
79 if (filename_len > exeext_len) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
80 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
81 /* Compare using an inlined copy of c_strncasecmp(), because |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
82 the filenames may have undergone a case conversion since |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
83 they were packaged. In other words, EXEEXT may be ".exe" |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
84 on one system and ".EXE" on another. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
85 const char *s1 = filename + filename_len - exeext_len; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
86 const char *s2 = exeext; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
87 for (; *s1 != '\0'; s1++, s2++) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
88 { |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
89 unsigned char c1 = *s1; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
90 unsigned char c2 = *s2; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
91 if (c_tolower (c1) != c_tolower (c2)) |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
92 goto simple_append; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
93 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
94 /* Insert ".bin" before EXEEXT or its equivalent. */ |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
95 memcpy (result, filename, filename_len - exeext_len); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
96 memcpy (result + filename_len - exeext_len, ".bin", 4); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
97 memcpy (result + filename_len - exeext_len + 4, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
98 filename + filename_len - exeext_len, |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
99 exeext_len + 1); |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
100 return result; |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
101 } |
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
102 } |
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
103 simple_append: |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
104 /* Simply append ".bin". */ |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
105 memcpy (result, filename, filename_len); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
106 memcpy (result + filename_len, ".bin", 4 + 1); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
107 return result; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
108 } |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
109 else |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
110 { |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
111 fprintf (stderr, "%s: %s\n", program_name, "memory exhausted"); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
112 exit (1); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
113 } |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
114 } |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
115 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
116 /* List of directories that contain the libraries. */ |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
117 static const char *libdirs[] = { LIBDIRS NULL }; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
118 /* Verify that at least one directory is given. */ |
13788
6f8ee3f6161c
rewrite int foo[2*X-1] to verify(X) or to int foo[X?1:-1]
Paul Eggert <eggert@cs.ucla.edu>
parents:
13397
diff
changeset
|
119 verify (sizeof (libdirs) / sizeof (libdirs[0]) > 1); |
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
120 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
121 /* Relocate the list of directories that contain the libraries. */ |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
122 static void |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
123 relocate_libdirs () |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
124 { |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
125 size_t i; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
126 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
127 for (i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
128 libdirs[i] = relocate (libdirs[i]); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
129 } |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
130 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
131 /* Activate the list of directories in the LIBPATHVAR. */ |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
132 static void |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
133 activate_libdirs () |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
134 { |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
135 const char *old_value; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
136 size_t total; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
137 size_t i; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
138 char *value; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
139 char *p; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
140 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
141 old_value = getenv (LIBPATHVAR); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
142 if (old_value == NULL) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
143 old_value = ""; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
144 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
145 total = 0; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
146 for (i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
147 total += strlen (libdirs[i]) + 1; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
148 total += strlen (old_value) + 1; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
149 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
150 value = (char *) malloc (total); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
151 if (value == NULL) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
152 { |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
153 fprintf (stderr, "%s: %s\n", program_name, "memory exhausted"); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
154 exit (1); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
155 } |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
156 p = value; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
157 for (i = 0; i < sizeof (libdirs) / sizeof (libdirs[0]) - 1; i++) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
158 { |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
159 size_t len = strlen (libdirs[i]); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
160 memcpy (p, libdirs[i], len); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
161 p += len; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
162 *p++ = ':'; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
163 } |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
164 if (old_value[0] != '\0') |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
165 strcpy (p, old_value); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
166 else |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
167 p[-1] = '\0'; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
168 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
169 if (setenv (LIBPATHVAR, value, 1) < 0) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
170 { |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
171 fprintf (stderr, "%s: %s\n", program_name, "memory exhausted"); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
172 exit (1); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
173 } |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
174 } |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
175 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
176 int |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
177 main (int argc, char *argv[]) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
178 { |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
179 char *full_program_name; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
180 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
181 /* Set the program name and perform preparations for |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
182 get_full_program_name() and relocate(). */ |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
183 set_program_name_and_installdir (argv[0], INSTALLPREFIX, INSTALLDIR); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
184 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
185 /* Get the full program path. (Important if accessed through a symlink.) */ |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
186 full_program_name = get_full_program_name (); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
187 if (full_program_name == NULL) |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
188 full_program_name = argv[0]; |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
189 |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
190 /* Invoke the real program, with suffix ".bin". */ |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
191 argv[0] = add_dotbin (full_program_name); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
192 relocate_libdirs (); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
193 activate_libdirs (); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
194 execv (argv[0], argv); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
195 fprintf (stderr, "%s: could not execute %s: %s\n", |
12421
e8d2c6fc33ad
Use spaces for indentation, not tabs.
Bruno Haible <bruno@clisp.org>
parents:
9547
diff
changeset
|
196 program_name, argv[0], strerror (errno)); |
8265
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
197 exit (127); |
20006894dae4
Infrastructure for relocatable installation, from GNU gettext.
Bruno Haible <bruno@clisp.org>
parents:
diff
changeset
|
198 } |