Skip to content

Commit d617c61

Browse files
committed
Update from gnulib.
1 parent 5b218d9 commit d617c61

File tree

3 files changed

+58
-24
lines changed

3 files changed

+58
-24
lines changed

libcharset/lib/ChangeLog

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
2009-03-25 Bruno Haible <bruno@clisp.org>
2+
3+
* relocatable.h: Update from gnulib.
4+
* relocatable.c: Likewise.
5+
16
2009-01-25 Bruno Haible <bruno@clisp.org>
27

38
Don't install charset.alias on MacOS X >= 10.3.

libcharset/lib/relocatable.c

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Provide relocatable packages.
2-
Copyright (C) 2003-2006 Free Software Foundation, Inc.
2+
Copyright (C) 2003-2006, 2008 Free Software Foundation, Inc.
33
Written by Bruno Haible <bruno@clisp.org>, 2003.
44
55
This program is free software; you can redistribute it and/or modify it
@@ -160,17 +160,18 @@ set_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg)
160160
/* Convenience function:
161161
Computes the current installation prefix, based on the original
162162
installation prefix, the original installation directory of a particular
163-
file, and the current pathname of this file. Returns NULL upon failure. */
163+
file, and the current pathname of this file.
164+
Returns it, freshly allocated. Returns NULL upon failure. */
164165
#ifdef IN_LIBRARY
165166
#define compute_curr_prefix local_compute_curr_prefix
166167
static
167168
#endif
168-
const char *
169+
char *
169170
compute_curr_prefix (const char *orig_installprefix,
170171
const char *orig_installdir,
171172
const char *curr_pathname)
172173
{
173-
const char *curr_installdir;
174+
char *curr_installdir;
174175
const char *rel_installdir;
175176

176177
if (curr_pathname == NULL)
@@ -254,8 +255,11 @@ compute_curr_prefix (const char *orig_installprefix,
254255
}
255256

256257
if (rp > rel_installdir)
257-
/* Unexpected: The curr_installdir does not end with rel_installdir. */
258-
return NULL;
258+
{
259+
/* Unexpected: The curr_installdir does not end with rel_installdir. */
260+
free (curr_installdir);
261+
return NULL;
262+
}
259263

260264
{
261265
size_t curr_prefix_len = cp - curr_installdir;
@@ -264,11 +268,16 @@ compute_curr_prefix (const char *orig_installprefix,
264268
curr_prefix = (char *) xmalloc (curr_prefix_len + 1);
265269
#ifdef NO_XMALLOC
266270
if (curr_prefix == NULL)
267-
return NULL;
271+
{
272+
free (curr_installdir);
273+
return NULL;
274+
}
268275
#endif
269276
memcpy (curr_prefix, curr_installdir, curr_prefix_len);
270277
curr_prefix[curr_prefix_len] = '\0';
271278

279+
free (curr_installdir);
280+
272281
return curr_prefix;
273282
}
274283
}
@@ -400,7 +409,9 @@ get_shared_library_fullname ()
400409
#endif /* PIC */
401410

402411
/* Returns the pathname, relocated according to the current installation
403-
directory. */
412+
directory.
413+
The returned string is either PATHNAME unmodified or a freshly allocated
414+
string that you can free with free() after casting it to 'char *'. */
404415
const char *
405416
relocate (const char *pathname)
406417
{
@@ -420,15 +431,19 @@ relocate (const char *pathname)
420431
orig_prefix. */
421432
const char *orig_installprefix = INSTALLPREFIX;
422433
const char *orig_installdir = INSTALLDIR;
423-
const char *curr_prefix_better;
434+
char *curr_prefix_better;
424435

425436
curr_prefix_better =
426437
compute_curr_prefix (orig_installprefix, orig_installdir,
427438
get_shared_library_fullname ());
428-
if (curr_prefix_better == NULL)
429-
curr_prefix_better = curr_prefix;
430439

431-
set_relocation_prefix (orig_installprefix, curr_prefix_better);
440+
set_relocation_prefix (orig_installprefix,
441+
curr_prefix_better != NULL
442+
? curr_prefix_better
443+
: curr_prefix);
444+
445+
if (curr_prefix_better != NULL)
446+
free (curr_prefix_better);
432447

433448
initialized = 1;
434449
}
@@ -442,9 +457,19 @@ relocate (const char *pathname)
442457
&& strncmp (pathname, orig_prefix, orig_prefix_len) == 0)
443458
{
444459
if (pathname[orig_prefix_len] == '\0')
445-
/* pathname equals orig_prefix. */
446-
return curr_prefix;
447-
if (ISSLASH (pathname[orig_prefix_len]))
460+
{
461+
/* pathname equals orig_prefix. */
462+
char *result = (char *) xmalloc (strlen (curr_prefix) + 1);
463+
464+
#ifdef NO_XMALLOC
465+
if (result != NULL)
466+
#endif
467+
{
468+
strcpy (result, curr_prefix);
469+
return result;
470+
}
471+
}
472+
else if (ISSLASH (pathname[orig_prefix_len]))
448473
{
449474
/* pathname starts with orig_prefix. */
450475
const char *pathname_tail = &pathname[orig_prefix_len];

libcharset/lib/relocatable.h

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* Provide relocatable packages.
2-
Copyright (C) 2003, 2005 Free Software Foundation, Inc.
2+
Copyright (C) 2003, 2005, 2008 Free Software Foundation, Inc.
33
Written by Bruno Haible <bruno@clisp.org>, 2003.
44
55
This program is free software; you can redistribute it and/or modify it
@@ -49,20 +49,24 @@ extern RELOCATABLE_DLL_EXPORTED void
4949
const char *curr_prefix);
5050

5151
/* Returns the pathname, relocated according to the current installation
52-
directory. */
52+
directory.
53+
The returned string is either PATHNAME unmodified or a freshly allocated
54+
string that you can free with free() after casting it to 'char *'. */
5355
extern const char * relocate (const char *pathname);
5456

55-
/* Memory management: relocate() leaks memory, because it has to construct
56-
a fresh pathname. If this is a problem because your program calls
57-
relocate() frequently, think about caching the result. */
57+
/* Memory management: relocate() potentially allocates memory, because it has
58+
to construct a fresh pathname. If this is a problem because your program
59+
calls relocate() frequently, think about caching the result. Or free the
60+
return value if it was different from the argument pathname. */
5861

5962
/* Convenience function:
6063
Computes the current installation prefix, based on the original
6164
installation prefix, the original installation directory of a particular
62-
file, and the current pathname of this file. Returns NULL upon failure. */
63-
extern const char * compute_curr_prefix (const char *orig_installprefix,
64-
const char *orig_installdir,
65-
const char *curr_pathname);
65+
file, and the current pathname of this file.
66+
Returns it, freshly allocated. Returns NULL upon failure. */
67+
extern char * compute_curr_prefix (const char *orig_installprefix,
68+
const char *orig_installdir,
69+
const char *curr_pathname);
6670

6771
#else
6872

0 commit comments

Comments
 (0)