X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Frelocwrapper.c;h=19dfaa383cb06222df17600d6c571b5913e7be93;hb=e5697c685644390cb2ec3f753a5547b73128f6b4;hp=c303803a8256cec8fa4cfda8331c737976618e8c;hpb=86f544b2e68eefe1410f8c7db3be1819a18dbfb9;p=gnulib.git diff --git a/lib/relocwrapper.c b/lib/relocwrapper.c index c303803a8..19dfaa383 100644 --- a/lib/relocwrapper.c +++ b/lib/relocwrapper.c @@ -1,11 +1,11 @@ /* Relocating wrapper program. - Copyright (C) 2003, 2005-2006 Free Software Foundation, Inc. + Copyright (C) 2003, 2005-2007, 2009-2010 Free Software Foundation, Inc. Written by Bruno Haible , 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 it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -13,21 +13,22 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software Foundation, - Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ + along with this program. If not, see . */ /* Dependencies: relocwrapper -> progname -> progreloc - -> xreadlink + -> areadlink + -> readlink + -> canonicalize-lgpl + -> malloca -> readlink - -> canonicalize - -> allocsa -> relocatable -> setenv - -> allocsa + -> malloca -> strerror + -> c-ctype Macros that need to be set while compiling this file: - ENABLE_RELOCATABLE 1 @@ -47,14 +48,12 @@ #include #include #include -#if HAVE_UNISTD_H -# include -#endif +#include #include #include "progname.h" #include "relocatable.h" -#include "setenv.h" +#include "c-ctype.h" /* Return a copy of the filename, with an extra ".bin" at the end. More generally, it replaces "${EXEEXT}" at the end with ".bin${EXEEXT}". */ @@ -67,35 +66,34 @@ add_dotbin (const char *filename) if (result != NULL) { if (sizeof (EXEEXT) > sizeof ("")) - { - /* EXEEXT handling. */ - const size_t exeext_len = sizeof (EXEEXT) - sizeof (""); - static const char exeext[] = EXEEXT; - if (filename_len > exeext_len) - { - /* Compare using an inlined copy of c_strncasecmp(), because - the filenames may have undergone a case conversion since - they were packaged. In other words, EXEEXT may be ".exe" - on one system and ".EXE" on another. */ - const char *s1 = filename + filename_len - exeext_len; - const char *s2 = exeext; - for (; *s1 != '\0'; s1++, s2++) - { - unsigned char c1 = *s1; - unsigned char c2 = *s2; - if ((c1 >= 'A' && c1 <= 'Z' ? c1 - 'A' + 'a' : c1) - != (c2 >= 'A' && c2 <= 'Z' ? c2 - 'A' + 'a' : c2)) - goto simple_append; - } - /* Insert ".bin" before EXEEXT or its equivalent. */ - memcpy (result, filename, filename_len - exeext_len); - memcpy (result + filename_len - exeext_len, ".bin", 4); - memcpy (result + filename_len - exeext_len + 4, - filename + filename_len - exeext_len, - exeext_len + 1); - return result; - } - } + { + /* EXEEXT handling. */ + const size_t exeext_len = sizeof (EXEEXT) - sizeof (""); + static const char exeext[] = EXEEXT; + if (filename_len > exeext_len) + { + /* Compare using an inlined copy of c_strncasecmp(), because + the filenames may have undergone a case conversion since + they were packaged. In other words, EXEEXT may be ".exe" + on one system and ".EXE" on another. */ + const char *s1 = filename + filename_len - exeext_len; + const char *s2 = exeext; + for (; *s1 != '\0'; s1++, s2++) + { + unsigned char c1 = *s1; + unsigned char c2 = *s2; + if (c_tolower (c1) != c_tolower (c2)) + goto simple_append; + } + /* Insert ".bin" before EXEEXT or its equivalent. */ + memcpy (result, filename, filename_len - exeext_len); + memcpy (result + filename_len - exeext_len, ".bin", 4); + memcpy (result + filename_len - exeext_len + 4, + filename + filename_len - exeext_len, + exeext_len + 1); + return result; + } + } simple_append: /* Simply append ".bin". */ memcpy (result, filename, filename_len); @@ -189,6 +187,6 @@ main (int argc, char *argv[]) activate_libdirs (); execv (argv[0], argv); fprintf (stderr, "%s: could not execute %s: %s\n", - program_name, argv[0], strerror (errno)); + program_name, argv[0], strerror (errno)); exit (127); }