|
version 1.1, 2012/02/21 22:57:48
|
version 1.1.1.2, 2012/05/29 09:29:43
|
|
Line 1
|
Line 1
|
| /* Relocating wrapper program. |
/* Relocating wrapper program. |
| Copyright (C) 2003, 2005-2007 Free Software Foundation, Inc. | Copyright (C) 2003, 2005-2007, 2009-2011 Free Software Foundation, Inc. |
| Written by Bruno Haible <bruno@clisp.org>, 2003. |
Written by Bruno Haible <bruno@clisp.org>, 2003. |
| |
|
| This program is free software: you can redistribute it and/or modify |
This program is free software: you can redistribute it and/or modify |
|
Line 20
|
Line 20
|
| -> progname |
-> progname |
| -> progreloc |
-> progreloc |
| -> areadlink |
-> areadlink |
| -> readlink | -> careadlinkat |
| | -> allocator |
| | -> readlink |
| -> canonicalize-lgpl |
-> canonicalize-lgpl |
| -> malloca |
-> malloca |
| -> readlink |
-> readlink |
| -> relocatable |
-> relocatable |
| -> setenv |
-> setenv |
| -> malloca |
-> malloca |
| -> strerror |
|
| -> c-ctype |
-> c-ctype |
| |
|
| Macros that need to be set while compiling this file: |
Macros that need to be set while compiling this file: |
|
Line 43
|
Line 44
|
| libc functions, no gettext(), no error(), no xmalloc(), no xsetenv(). |
libc functions, no gettext(), no error(), no xmalloc(), no xsetenv(). |
| */ |
*/ |
| |
|
| |
#define _GL_USE_STDLIB_ALLOC 1 |
| #include <config.h> |
#include <config.h> |
| |
|
| #include <stdio.h> |
#include <stdio.h> |
|
Line 54
|
Line 56
|
| #include "progname.h" |
#include "progname.h" |
| #include "relocatable.h" |
#include "relocatable.h" |
| #include "c-ctype.h" |
#include "c-ctype.h" |
| |
#include "verify.h" |
| |
|
| |
/* Use the system functions, not the gnulib overrides in this file. */ |
| |
#undef fprintf |
| |
|
| /* Return a copy of the filename, with an extra ".bin" at the end. |
/* Return a copy of the filename, with an extra ".bin" at the end. |
| More generally, it replaces "${EXEEXT}" at the end with ".bin${EXEEXT}". */ |
More generally, it replaces "${EXEEXT}" at the end with ".bin${EXEEXT}". */ |
| static char * |
static char * |
|
Line 66 add_dotbin (const char *filename)
|
Line 72 add_dotbin (const char *filename)
|
| if (result != NULL) |
if (result != NULL) |
| { |
{ |
| if (sizeof (EXEEXT) > sizeof ("")) |
if (sizeof (EXEEXT) > sizeof ("")) |
| { | { |
| /* EXEEXT handling. */ | /* EXEEXT handling. */ |
| const size_t exeext_len = sizeof (EXEEXT) - sizeof (""); | const size_t exeext_len = sizeof (EXEEXT) - sizeof (""); |
| static const char exeext[] = EXEEXT; | static const char exeext[] = EXEEXT; |
| if (filename_len > exeext_len) | if (filename_len > exeext_len) |
| { | { |
| /* Compare using an inlined copy of c_strncasecmp(), because | /* Compare using an inlined copy of c_strncasecmp(), because |
| the filenames may have undergone a case conversion since | the filenames may have undergone a case conversion since |
| they were packaged. In other words, EXEEXT may be ".exe" | they were packaged. In other words, EXEEXT may be ".exe" |
| on one system and ".EXE" on another. */ | on one system and ".EXE" on another. */ |
| const char *s1 = filename + filename_len - exeext_len; | const char *s1 = filename + filename_len - exeext_len; |
| const char *s2 = exeext; | const char *s2 = exeext; |
| for (; *s1 != '\0'; s1++, s2++) | for (; *s1 != '\0'; s1++, s2++) |
| { | { |
| unsigned char c1 = *s1; | unsigned char c1 = *s1; |
| unsigned char c2 = *s2; | unsigned char c2 = *s2; |
| if (c_tolower (c1) != c_tolower (c2)) | if (c_tolower (c1) != c_tolower (c2)) |
| goto simple_append; | goto simple_append; |
| } | } |
| /* Insert ".bin" before EXEEXT or its equivalent. */ | /* Insert ".bin" before EXEEXT or its equivalent. */ |
| memcpy (result, filename, filename_len - exeext_len); | memcpy (result, filename, filename_len - exeext_len); |
| memcpy (result + filename_len - exeext_len, ".bin", 4); | memcpy (result + filename_len - exeext_len, ".bin", 4); |
| memcpy (result + filename_len - exeext_len + 4, | memcpy (result + filename_len - exeext_len + 4, |
| filename + filename_len - exeext_len, | filename + filename_len - exeext_len, |
| exeext_len + 1); | exeext_len + 1); |
| return result; | return result; |
| } | } |
| } | } |
| simple_append: |
simple_append: |
| /* Simply append ".bin". */ |
/* Simply append ".bin". */ |
| memcpy (result, filename, filename_len); |
memcpy (result, filename, filename_len); |
|
Line 110 add_dotbin (const char *filename)
|
Line 116 add_dotbin (const char *filename)
|
| /* List of directories that contain the libraries. */ |
/* List of directories that contain the libraries. */ |
| static const char *libdirs[] = { LIBDIRS NULL }; |
static const char *libdirs[] = { LIBDIRS NULL }; |
| /* Verify that at least one directory is given. */ |
/* Verify that at least one directory is given. */ |
| typedef int verify1[2 * (sizeof (libdirs) / sizeof (libdirs[0]) > 1) - 1]; | verify (sizeof (libdirs) / sizeof (libdirs[0]) > 1); |
| |
|
| /* Relocate the list of directories that contain the libraries. */ |
/* Relocate the list of directories that contain the libraries. */ |
| static void |
static void |
|
Line 187 main (int argc, char *argv[])
|
Line 193 main (int argc, char *argv[])
|
| activate_libdirs (); |
activate_libdirs (); |
| execv (argv[0], argv); |
execv (argv[0], argv); |
| fprintf (stderr, "%s: could not execute %s: %s\n", |
fprintf (stderr, "%s: could not execute %s: %s\n", |
| program_name, argv[0], strerror (errno)); | program_name, argv[0], strerror (errno)); |
| exit (127); |
exit (127); |
| } |
} |