annotate intl/relocatable.c @ 1308:3e4de397d062 trunk

[svn] - give the labels on the left proper identifiers
author nenolod
date Mon, 19 Jun 2006 01:33:30 -0700
parents cb178e5ad177
children f12d7e208b43
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
1 /* Provide relocatable packages.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
2 Copyright (C) 2003 Free Software Foundation, Inc.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
3 Written by Bruno Haible <bruno@clisp.org>, 2003.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
4
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
5 This program is free software; you can redistribute it and/or modify it
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
6 under the terms of the GNU Library General Public License as published
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
7 by the Free Software Foundation; either version 2, or (at your option)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
8 any later version.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
9
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
10 This program is distributed in the hope that it will be useful,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
13 Library General Public License for more details.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
14
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
15 You should have received a copy of the GNU Library General Public
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
16 License along with this program; if not, write to the Free Software
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
17 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
18 USA. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
19
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
20
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
21 /* Tell glibc's <stdio.h> to provide a prototype for getline().
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
22 This must come before <config.h> because <config.h> may include
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
23 <features.h>, and once <features.h> has been included, it's too late. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
24 #ifndef _GNU_SOURCE
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
25 # define _GNU_SOURCE 1
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
26 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
27
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
28 #ifdef HAVE_CONFIG_H
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
29 # include "config.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
30 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
31
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
32 /* Specification. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
33 #include "relocatable.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
34
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
35 #if ENABLE_RELOCATABLE
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
36
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
37 #include <stddef.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
38 #include <stdio.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
39 #include <stdlib.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
40 #include <string.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
41
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
42 #ifdef NO_XMALLOC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
43 # define xmalloc malloc
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
44 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
45 # include "xmalloc.h"
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
46 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
47
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
48 #if DEPENDS_ON_LIBCHARSET
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
49 # include <libcharset.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
50 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
51 #if DEPENDS_ON_LIBICONV && HAVE_ICONV
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
52 # include <iconv.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
53 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
54 #if DEPENDS_ON_LIBINTL && ENABLE_NLS
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
55 # include <libintl.h>
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
56 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
57
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
58 /* Faked cheap 'bool'. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
59 #undef bool
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
60 #undef false
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
61 #undef true
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
62 #define bool int
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
63 #define false 0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
64 #define true 1
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
65
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
66 /* Pathname support.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
67 ISSLASH(C) tests whether C is a directory separator character.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
68 IS_PATH_WITH_DIR(P) tests whether P contains a directory specification.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
69 */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
70 #if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
71 /* Win32, OS/2, DOS */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
72 # define ISSLASH(C) ((C) == '/' || (C) == '\\')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
73 # define HAS_DEVICE(P) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
74 ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
75 && (P)[1] == ':')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
76 # define IS_PATH_WITH_DIR(P) \
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
77 (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
78 # define FILESYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
79 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
80 /* Unix */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
81 # define ISSLASH(C) ((C) == '/')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
82 # define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
83 # define FILESYSTEM_PREFIX_LEN(P) 0
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
84 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
85
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
86 /* Original installation prefix. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
87 static char *orig_prefix;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
88 static size_t orig_prefix_len;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
89 /* Current installation prefix. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
90 static char *curr_prefix;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
91 static size_t curr_prefix_len;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
92 /* These prefixes do not end in a slash. Anything that will be concatenated
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
93 to them must start with a slash. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
94
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
95 /* Sets the original and the current installation prefix of this module.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
96 Relocation simply replaces a pathname starting with the original prefix
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
97 by the corresponding pathname with the current prefix instead. Both
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
98 prefixes should be directory names without trailing slash (i.e. use ""
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
99 instead of "/"). */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
100 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
101 set_this_relocation_prefix (const char *orig_prefix_arg,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
102 const char *curr_prefix_arg)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
103 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
104 if (orig_prefix_arg != NULL && curr_prefix_arg != NULL
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
105 /* Optimization: if orig_prefix and curr_prefix are equal, the
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
106 relocation is a nop. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
107 && strcmp (orig_prefix_arg, curr_prefix_arg) != 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
108 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
109 /* Duplicate the argument strings. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
110 char *memory;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
111
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
112 orig_prefix_len = strlen (orig_prefix_arg);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
113 curr_prefix_len = strlen (curr_prefix_arg);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
114 memory = (char *) xmalloc (orig_prefix_len + 1 + curr_prefix_len + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
115 #ifdef NO_XMALLOC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
116 if (memory != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
117 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
118 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
119 memcpy (memory, orig_prefix_arg, orig_prefix_len + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
120 orig_prefix = memory;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
121 memory += orig_prefix_len + 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
122 memcpy (memory, curr_prefix_arg, curr_prefix_len + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
123 curr_prefix = memory;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
124 return;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
125 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
126 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
127 orig_prefix = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
128 curr_prefix = NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
129 /* Don't worry about wasted memory here - this function is usually only
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
130 called once. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
131 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
132
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
133 /* Sets the original and the current installation prefix of the package.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
134 Relocation simply replaces a pathname starting with the original prefix
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
135 by the corresponding pathname with the current prefix instead. Both
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
136 prefixes should be directory names without trailing slash (i.e. use ""
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
137 instead of "/"). */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
138 void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
139 set_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
140 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
141 set_this_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
142
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
143 /* Now notify all dependent libraries. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
144 #if DEPENDS_ON_LIBCHARSET
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
145 libcharset_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
146 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
147 #if DEPENDS_ON_LIBICONV && HAVE_ICONV && _LIBICONV_VERSION >= 0x0109
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
148 libiconv_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
149 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
150 #if DEPENDS_ON_LIBINTL && ENABLE_NLS && defined libintl_set_relocation_prefix
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
151 libintl_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
152 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
153 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
154
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
155 /* Convenience function:
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
156 Computes the current installation prefix, based on the original
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
157 installation prefix, the original installation directory of a particular
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
158 file, and the current pathname of this file. Returns NULL upon failure. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
159 #ifdef IN_LIBRARY
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
160 #define compute_curr_prefix local_compute_curr_prefix
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
161 static
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
162 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
163 const char *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
164 compute_curr_prefix (const char *orig_installprefix,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
165 const char *orig_installdir,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
166 const char *curr_pathname)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
167 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
168 const char *curr_installdir;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
169 const char *rel_installdir;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
170
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
171 if (curr_pathname == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
172 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
173
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
174 /* Determine the relative installation directory, relative to the prefix.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
175 This is simply the difference between orig_installprefix and
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
176 orig_installdir. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
177 if (strncmp (orig_installprefix, orig_installdir, strlen (orig_installprefix))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
178 != 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
179 /* Shouldn't happen - nothing should be installed outside $(prefix). */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
180 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
181 rel_installdir = orig_installdir + strlen (orig_installprefix);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
182
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
183 /* Determine the current installation directory. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
184 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
185 const char *p_base = curr_pathname + FILESYSTEM_PREFIX_LEN (curr_pathname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
186 const char *p = curr_pathname + strlen (curr_pathname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
187 char *q;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
188
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
189 while (p > p_base)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
190 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
191 p--;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
192 if (ISSLASH (*p))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
193 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
194 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
195
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
196 q = (char *) xmalloc (p - curr_pathname + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
197 #ifdef NO_XMALLOC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
198 if (q == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
199 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
200 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
201 memcpy (q, curr_pathname, p - curr_pathname);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
202 q[p - curr_pathname] = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
203 curr_installdir = q;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
204 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
205
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
206 /* Compute the current installation prefix by removing the trailing
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
207 rel_installdir from it. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
208 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
209 const char *rp = rel_installdir + strlen (rel_installdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
210 const char *cp = curr_installdir + strlen (curr_installdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
211 const char *cp_base =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
212 curr_installdir + FILESYSTEM_PREFIX_LEN (curr_installdir);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
213
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
214 while (rp > rel_installdir && cp > cp_base)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
215 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
216 bool same = false;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
217 const char *rpi = rp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
218 const char *cpi = cp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
219
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
220 while (rpi > rel_installdir && cpi > cp_base)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
221 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
222 rpi--;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
223 cpi--;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
224 if (ISSLASH (*rpi) || ISSLASH (*cpi))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
225 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
226 if (ISSLASH (*rpi) && ISSLASH (*cpi))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
227 same = true;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
228 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
229 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
230 #if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
231 /* Win32, OS/2, DOS - case insignificant filesystem */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
232 if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
233 != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
234 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
235 #else
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
236 if (*rpi != *cpi)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
237 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
238 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
239 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
240 if (!same)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
241 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
242 /* The last pathname component was the same. opi and cpi now point
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
243 to the slash before it. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
244 rp = rpi;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
245 cp = cpi;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
246 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
247
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
248 if (rp > rel_installdir)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
249 /* Unexpected: The curr_installdir does not end with rel_installdir. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
250 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
251
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
252 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
253 size_t curr_prefix_len = cp - curr_installdir;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
254 char *curr_prefix;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
255
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
256 curr_prefix = (char *) xmalloc (curr_prefix_len + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
257 #ifdef NO_XMALLOC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
258 if (curr_prefix == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
259 return NULL;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
260 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
261 memcpy (curr_prefix, curr_installdir, curr_prefix_len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
262 curr_prefix[curr_prefix_len] = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
263
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
264 return curr_prefix;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
265 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
266 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
267 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
268
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
269 #if defined PIC && defined INSTALLDIR
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
270
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
271 /* Full pathname of shared library, or NULL. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
272 static char *shared_library_fullname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
273
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
274 #if defined _WIN32 || defined __WIN32__
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
275
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
276 /* Determine the full pathname of the shared library when it is loaded. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
277
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
278 BOOL WINAPI
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
279 DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
280 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
281 (void) reserved;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
282
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
283 if (event == DLL_PROCESS_ATTACH)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
284 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
285 /* The DLL is being loaded into an application's address range. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
286 static char location[MAX_PATH];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
287
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
288 if (!GetModuleFileName (module_handle, location, sizeof (location)))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
289 /* Shouldn't happen. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
290 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
291
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
292 if (!IS_PATH_WITH_DIR (location))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
293 /* Shouldn't happen. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
294 return FALSE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
295
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
296 shared_library_fullname = strdup (location);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
297 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
298
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
299 return TRUE;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
300 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
301
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
302 #else /* Unix */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
303
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
304 static void
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
305 find_shared_library_fullname ()
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
306 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
307 #ifdef __linux__
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
308 FILE *fp;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
309
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
310 /* Open the current process' maps file. It describes one VMA per line. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
311 fp = fopen ("/proc/self/maps", "r");
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
312 if (fp)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
313 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
314 unsigned long address = (unsigned long) &find_shared_library_fullname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
315 for (;;)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
316 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
317 unsigned long start, end;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
318 int c;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
319
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
320 if (fscanf (fp, "%lx-%lx", &start, &end) != 2)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
321 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
322 if (address >= start && address <= end - 1)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
323 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
324 /* Found it. Now see if this line contains a filename. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
325 while (c = getc (fp), c != EOF && c != '\n' && c != '/')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
326 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
327 if (c == '/')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
328 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
329 size_t size;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
330 int len;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
331
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
332 ungetc (c, fp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
333 shared_library_fullname = NULL; size = 0;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
334 len = getline (&shared_library_fullname, &size, fp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
335 if (len >= 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
336 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
337 /* Success: filled shared_library_fullname. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
338 if (len > 0 && shared_library_fullname[len - 1] == '\n')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
339 shared_library_fullname[len - 1] = '\0';
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
340 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
341 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
342 break;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
343 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
344 while (c = getc (fp), c != EOF && c != '\n')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
345 continue;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
346 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
347 fclose (fp);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
348 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
349 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
350 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
351
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
352 #endif /* WIN32 / Unix */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
353
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
354 /* Return the full pathname of the current shared library.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
355 Return NULL if unknown.
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
356 Guaranteed to work only on Linux and Woe32. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
357 static char *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
358 get_shared_library_fullname ()
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
359 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
360 #if !(defined _WIN32 || defined __WIN32__)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
361 static bool tried_find_shared_library_fullname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
362 if (!tried_find_shared_library_fullname)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
363 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
364 find_shared_library_fullname ();
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
365 tried_find_shared_library_fullname = true;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
366 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
367 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
368 return shared_library_fullname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
369 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
370
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
371 #endif /* PIC */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
372
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
373 /* Returns the pathname, relocated according to the current installation
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
374 directory. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
375 const char *
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
376 relocate (const char *pathname)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
377 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
378 #if defined PIC && defined INSTALLDIR
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
379 static int initialized;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
380
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
381 /* Initialization code for a shared library. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
382 if (!initialized)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
383 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
384 /* At this point, orig_prefix and curr_prefix likely have already been
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
385 set through the main program's set_program_name_and_installdir
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
386 function. This is sufficient in the case that the library has
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
387 initially been installed in the same orig_prefix. But we can do
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
388 better, to also cover the cases that 1. it has been installed
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
389 in a different prefix before being moved to orig_prefix and (later)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
390 to curr_prefix, 2. unlike the program, it has not moved away from
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
391 orig_prefix. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
392 const char *orig_installprefix = INSTALLPREFIX;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
393 const char *orig_installdir = INSTALLDIR;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
394 const char *curr_prefix_better;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
395
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
396 curr_prefix_better =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
397 compute_curr_prefix (orig_installprefix, orig_installdir,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
398 get_shared_library_fullname ());
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
399 if (curr_prefix_better == NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
400 curr_prefix_better = curr_prefix;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
401
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
402 set_relocation_prefix (orig_installprefix, curr_prefix_better);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
403
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
404 initialized = 1;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
405 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
406 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
407
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
408 /* Note: It is not necessary to perform case insensitive comparison here,
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
409 even for DOS-like filesystems, because the pathname argument was
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
410 typically created from the same Makefile variable as orig_prefix came
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
411 from. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
412 if (orig_prefix != NULL && curr_prefix != NULL
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
413 && strncmp (pathname, orig_prefix, orig_prefix_len) == 0)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
414 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
415 if (pathname[orig_prefix_len] == '\0')
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
416 /* pathname equals orig_prefix. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
417 return curr_prefix;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
418 if (ISSLASH (pathname[orig_prefix_len]))
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
419 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
420 /* pathname starts with orig_prefix. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
421 const char *pathname_tail = &pathname[orig_prefix_len];
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
422 char *result =
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
423 (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
424
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
425 #ifdef NO_XMALLOC
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
426 if (result != NULL)
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
427 #endif
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
428 {
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
429 memcpy (result, curr_prefix, curr_prefix_len);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
430 strcpy (result + curr_prefix_len, pathname_tail);
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
431 return result;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
432 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
433 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
434 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
435 /* Nothing to relocate. */
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
436 return pathname;
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
437 }
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
438
cb178e5ad177 [svn] Import audacious source.
nenolod
parents:
diff changeset
439 #endif