OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-old/] [gcc-4.2.2/] [intl/] [relocatable.c] - Diff between revs 154 and 816

Go to most recent revision | Only display areas with differences | Details | Blame | View Log

Rev 154 Rev 816
/* Provide relocatable packages.
/* Provide relocatable packages.
   Copyright (C) 2003 Free Software Foundation, Inc.
   Copyright (C) 2003 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 it
   This program is free software; you can redistribute it and/or modify it
   under the terms of the GNU Library General Public License as published
   under the terms of the GNU Library General Public License as published
   by the Free Software Foundation; either version 2, or (at your option)
   by the Free Software Foundation; either version 2, or (at your option)
   any later version.
   any later version.
 
 
   This program is distributed in the hope that it will be useful,
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.
   Library General Public License for more details.
 
 
   You should have received a copy of the GNU Library General Public
   You should have received a copy of the GNU Library General Public
   License along with this program; if not, write to the Free Software
   License along with this program; if not, write to the Free Software
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
   USA.  */
   USA.  */
 
 
 
 
/* Tell glibc's <stdio.h> to provide a prototype for getline().
/* Tell glibc's <stdio.h> to provide a prototype for getline().
   This must come before <config.h> because <config.h> may include
   This must come before <config.h> because <config.h> may include
   <features.h>, and once <features.h> has been included, it's too late.  */
   <features.h>, and once <features.h> has been included, it's too late.  */
#ifndef _GNU_SOURCE
#ifndef _GNU_SOURCE
# define _GNU_SOURCE    1
# define _GNU_SOURCE    1
#endif
#endif
 
 
#ifdef HAVE_CONFIG_H
#ifdef HAVE_CONFIG_H
# include "config.h"
# include "config.h"
#endif
#endif
 
 
/* Specification.  */
/* Specification.  */
#include "relocatable.h"
#include "relocatable.h"
 
 
#if ENABLE_RELOCATABLE
#if ENABLE_RELOCATABLE
 
 
#include <stddef.h>
#include <stddef.h>
#include <stdio.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
 
 
#ifdef NO_XMALLOC
#ifdef NO_XMALLOC
# define xmalloc malloc
# define xmalloc malloc
#else
#else
# include "xmalloc.h"
# include "xmalloc.h"
#endif
#endif
 
 
#if DEPENDS_ON_LIBCHARSET
#if DEPENDS_ON_LIBCHARSET
# include <libcharset.h>
# include <libcharset.h>
#endif
#endif
#if DEPENDS_ON_LIBICONV && HAVE_ICONV
#if DEPENDS_ON_LIBICONV && HAVE_ICONV
# include <iconv.h>
# include <iconv.h>
#endif
#endif
#if DEPENDS_ON_LIBINTL && ENABLE_NLS
#if DEPENDS_ON_LIBINTL && ENABLE_NLS
# include <libintl.h>
# include <libintl.h>
#endif
#endif
 
 
/* Faked cheap 'bool'.  */
/* Faked cheap 'bool'.  */
#undef bool
#undef bool
#undef false
#undef false
#undef true
#undef true
#define bool int
#define bool int
#define false 0
#define false 0
#define true 1
#define true 1
 
 
/* Pathname support.
/* Pathname support.
   ISSLASH(C)           tests whether C is a directory separator character.
   ISSLASH(C)           tests whether C is a directory separator character.
   IS_PATH_WITH_DIR(P)  tests whether P contains a directory specification.
   IS_PATH_WITH_DIR(P)  tests whether P contains a directory specification.
 */
 */
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
  /* Win32, OS/2, DOS */
  /* Win32, OS/2, DOS */
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
# define ISSLASH(C) ((C) == '/' || (C) == '\\')
# define HAS_DEVICE(P) \
# define HAS_DEVICE(P) \
    ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
    ((((P)[0] >= 'A' && (P)[0] <= 'Z') || ((P)[0] >= 'a' && (P)[0] <= 'z')) \
     && (P)[1] == ':')
     && (P)[1] == ':')
# define IS_PATH_WITH_DIR(P) \
# define IS_PATH_WITH_DIR(P) \
    (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
    (strchr (P, '/') != NULL || strchr (P, '\\') != NULL || HAS_DEVICE (P))
# define FILESYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
# define FILESYSTEM_PREFIX_LEN(P) (HAS_DEVICE (P) ? 2 : 0)
#else
#else
  /* Unix */
  /* Unix */
# define ISSLASH(C) ((C) == '/')
# define ISSLASH(C) ((C) == '/')
# define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
# define IS_PATH_WITH_DIR(P) (strchr (P, '/') != NULL)
# define FILESYSTEM_PREFIX_LEN(P) 0
# define FILESYSTEM_PREFIX_LEN(P) 0
#endif
#endif
 
 
/* Original installation prefix.  */
/* Original installation prefix.  */
static char *orig_prefix;
static char *orig_prefix;
static size_t orig_prefix_len;
static size_t orig_prefix_len;
/* Current installation prefix.  */
/* Current installation prefix.  */
static char *curr_prefix;
static char *curr_prefix;
static size_t curr_prefix_len;
static size_t curr_prefix_len;
/* These prefixes do not end in a slash.  Anything that will be concatenated
/* These prefixes do not end in a slash.  Anything that will be concatenated
   to them must start with a slash.  */
   to them must start with a slash.  */
 
 
/* Sets the original and the current installation prefix of this module.
/* Sets the original and the current installation prefix of this module.
   Relocation simply replaces a pathname starting with the original prefix
   Relocation simply replaces a pathname starting with the original prefix
   by the corresponding pathname with the current prefix instead.  Both
   by the corresponding pathname with the current prefix instead.  Both
   prefixes should be directory names without trailing slash (i.e. use ""
   prefixes should be directory names without trailing slash (i.e. use ""
   instead of "/").  */
   instead of "/").  */
static void
static void
set_this_relocation_prefix (const char *orig_prefix_arg,
set_this_relocation_prefix (const char *orig_prefix_arg,
                            const char *curr_prefix_arg)
                            const char *curr_prefix_arg)
{
{
  if (orig_prefix_arg != NULL && curr_prefix_arg != NULL
  if (orig_prefix_arg != NULL && curr_prefix_arg != NULL
      /* Optimization: if orig_prefix and curr_prefix are equal, the
      /* Optimization: if orig_prefix and curr_prefix are equal, the
         relocation is a nop.  */
         relocation is a nop.  */
      && strcmp (orig_prefix_arg, curr_prefix_arg) != 0)
      && strcmp (orig_prefix_arg, curr_prefix_arg) != 0)
    {
    {
      /* Duplicate the argument strings.  */
      /* Duplicate the argument strings.  */
      char *memory;
      char *memory;
 
 
      orig_prefix_len = strlen (orig_prefix_arg);
      orig_prefix_len = strlen (orig_prefix_arg);
      curr_prefix_len = strlen (curr_prefix_arg);
      curr_prefix_len = strlen (curr_prefix_arg);
      memory = (char *) xmalloc (orig_prefix_len + 1 + curr_prefix_len + 1);
      memory = (char *) xmalloc (orig_prefix_len + 1 + curr_prefix_len + 1);
#ifdef NO_XMALLOC
#ifdef NO_XMALLOC
      if (memory != NULL)
      if (memory != NULL)
#endif
#endif
        {
        {
          memcpy (memory, orig_prefix_arg, orig_prefix_len + 1);
          memcpy (memory, orig_prefix_arg, orig_prefix_len + 1);
          orig_prefix = memory;
          orig_prefix = memory;
          memory += orig_prefix_len + 1;
          memory += orig_prefix_len + 1;
          memcpy (memory, curr_prefix_arg, curr_prefix_len + 1);
          memcpy (memory, curr_prefix_arg, curr_prefix_len + 1);
          curr_prefix = memory;
          curr_prefix = memory;
          return;
          return;
        }
        }
    }
    }
  orig_prefix = NULL;
  orig_prefix = NULL;
  curr_prefix = NULL;
  curr_prefix = NULL;
  /* Don't worry about wasted memory here - this function is usually only
  /* Don't worry about wasted memory here - this function is usually only
     called once.  */
     called once.  */
}
}
 
 
/* Sets the original and the current installation prefix of the package.
/* Sets the original and the current installation prefix of the package.
   Relocation simply replaces a pathname starting with the original prefix
   Relocation simply replaces a pathname starting with the original prefix
   by the corresponding pathname with the current prefix instead.  Both
   by the corresponding pathname with the current prefix instead.  Both
   prefixes should be directory names without trailing slash (i.e. use ""
   prefixes should be directory names without trailing slash (i.e. use ""
   instead of "/").  */
   instead of "/").  */
void
void
set_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg)
set_relocation_prefix (const char *orig_prefix_arg, const char *curr_prefix_arg)
{
{
  set_this_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
  set_this_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
 
 
  /* Now notify all dependent libraries.  */
  /* Now notify all dependent libraries.  */
#if DEPENDS_ON_LIBCHARSET
#if DEPENDS_ON_LIBCHARSET
  libcharset_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
  libcharset_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
#endif
#endif
#if DEPENDS_ON_LIBICONV && HAVE_ICONV && _LIBICONV_VERSION >= 0x0109
#if DEPENDS_ON_LIBICONV && HAVE_ICONV && _LIBICONV_VERSION >= 0x0109
  libiconv_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
  libiconv_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
#endif
#endif
#if DEPENDS_ON_LIBINTL && ENABLE_NLS && defined libintl_set_relocation_prefix
#if DEPENDS_ON_LIBINTL && ENABLE_NLS && defined libintl_set_relocation_prefix
  libintl_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
  libintl_set_relocation_prefix (orig_prefix_arg, curr_prefix_arg);
#endif
#endif
}
}
 
 
/* Convenience function:
/* Convenience function:
   Computes the current installation prefix, based on the original
   Computes the current installation prefix, based on the original
   installation prefix, the original installation directory of a particular
   installation prefix, the original installation directory of a particular
   file, and the current pathname of this file.  Returns NULL upon failure.  */
   file, and the current pathname of this file.  Returns NULL upon failure.  */
#ifdef IN_LIBRARY
#ifdef IN_LIBRARY
#define compute_curr_prefix local_compute_curr_prefix
#define compute_curr_prefix local_compute_curr_prefix
static
static
#endif
#endif
const char *
const char *
compute_curr_prefix (const char *orig_installprefix,
compute_curr_prefix (const char *orig_installprefix,
                     const char *orig_installdir,
                     const char *orig_installdir,
                     const char *curr_pathname)
                     const char *curr_pathname)
{
{
  const char *curr_installdir;
  const char *curr_installdir;
  const char *rel_installdir;
  const char *rel_installdir;
 
 
  if (curr_pathname == NULL)
  if (curr_pathname == NULL)
    return NULL;
    return NULL;
 
 
  /* Determine the relative installation directory, relative to the prefix.
  /* Determine the relative installation directory, relative to the prefix.
     This is simply the difference between orig_installprefix and
     This is simply the difference between orig_installprefix and
     orig_installdir.  */
     orig_installdir.  */
  if (strncmp (orig_installprefix, orig_installdir, strlen (orig_installprefix))
  if (strncmp (orig_installprefix, orig_installdir, strlen (orig_installprefix))
      != 0)
      != 0)
    /* Shouldn't happen - nothing should be installed outside $(prefix).  */
    /* Shouldn't happen - nothing should be installed outside $(prefix).  */
    return NULL;
    return NULL;
  rel_installdir = orig_installdir + strlen (orig_installprefix);
  rel_installdir = orig_installdir + strlen (orig_installprefix);
 
 
  /* Determine the current installation directory.  */
  /* Determine the current installation directory.  */
  {
  {
    const char *p_base = curr_pathname + FILESYSTEM_PREFIX_LEN (curr_pathname);
    const char *p_base = curr_pathname + FILESYSTEM_PREFIX_LEN (curr_pathname);
    const char *p = curr_pathname + strlen (curr_pathname);
    const char *p = curr_pathname + strlen (curr_pathname);
    char *q;
    char *q;
 
 
    while (p > p_base)
    while (p > p_base)
      {
      {
        p--;
        p--;
        if (ISSLASH (*p))
        if (ISSLASH (*p))
          break;
          break;
      }
      }
 
 
    q = (char *) xmalloc (p - curr_pathname + 1);
    q = (char *) xmalloc (p - curr_pathname + 1);
#ifdef NO_XMALLOC
#ifdef NO_XMALLOC
    if (q == NULL)
    if (q == NULL)
      return NULL;
      return NULL;
#endif
#endif
    memcpy (q, curr_pathname, p - curr_pathname);
    memcpy (q, curr_pathname, p - curr_pathname);
    q[p - curr_pathname] = '\0';
    q[p - curr_pathname] = '\0';
    curr_installdir = q;
    curr_installdir = q;
  }
  }
 
 
  /* Compute the current installation prefix by removing the trailing
  /* Compute the current installation prefix by removing the trailing
     rel_installdir from it.  */
     rel_installdir from it.  */
  {
  {
    const char *rp = rel_installdir + strlen (rel_installdir);
    const char *rp = rel_installdir + strlen (rel_installdir);
    const char *cp = curr_installdir + strlen (curr_installdir);
    const char *cp = curr_installdir + strlen (curr_installdir);
    const char *cp_base =
    const char *cp_base =
      curr_installdir + FILESYSTEM_PREFIX_LEN (curr_installdir);
      curr_installdir + FILESYSTEM_PREFIX_LEN (curr_installdir);
 
 
    while (rp > rel_installdir && cp > cp_base)
    while (rp > rel_installdir && cp > cp_base)
      {
      {
        bool same = false;
        bool same = false;
        const char *rpi = rp;
        const char *rpi = rp;
        const char *cpi = cp;
        const char *cpi = cp;
 
 
        while (rpi > rel_installdir && cpi > cp_base)
        while (rpi > rel_installdir && cpi > cp_base)
          {
          {
            rpi--;
            rpi--;
            cpi--;
            cpi--;
            if (ISSLASH (*rpi) || ISSLASH (*cpi))
            if (ISSLASH (*rpi) || ISSLASH (*cpi))
              {
              {
                if (ISSLASH (*rpi) && ISSLASH (*cpi))
                if (ISSLASH (*rpi) && ISSLASH (*cpi))
                  same = true;
                  same = true;
                break;
                break;
              }
              }
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
#if defined _WIN32 || defined __WIN32__ || defined __EMX__ || defined __DJGPP__
            /* Win32, OS/2, DOS - case insignificant filesystem */
            /* Win32, OS/2, DOS - case insignificant filesystem */
            if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi)
            if ((*rpi >= 'a' && *rpi <= 'z' ? *rpi - 'a' + 'A' : *rpi)
                != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi))
                != (*cpi >= 'a' && *cpi <= 'z' ? *cpi - 'a' + 'A' : *cpi))
              break;
              break;
#else
#else
            if (*rpi != *cpi)
            if (*rpi != *cpi)
              break;
              break;
#endif
#endif
          }
          }
        if (!same)
        if (!same)
          break;
          break;
        /* The last pathname component was the same.  opi and cpi now point
        /* The last pathname component was the same.  opi and cpi now point
           to the slash before it.  */
           to the slash before it.  */
        rp = rpi;
        rp = rpi;
        cp = cpi;
        cp = cpi;
      }
      }
 
 
    if (rp > rel_installdir)
    if (rp > rel_installdir)
      /* Unexpected: The curr_installdir does not end with rel_installdir.  */
      /* Unexpected: The curr_installdir does not end with rel_installdir.  */
      return NULL;
      return NULL;
 
 
    {
    {
      size_t curr_prefix_len = cp - curr_installdir;
      size_t curr_prefix_len = cp - curr_installdir;
      char *curr_prefix;
      char *curr_prefix;
 
 
      curr_prefix = (char *) xmalloc (curr_prefix_len + 1);
      curr_prefix = (char *) xmalloc (curr_prefix_len + 1);
#ifdef NO_XMALLOC
#ifdef NO_XMALLOC
      if (curr_prefix == NULL)
      if (curr_prefix == NULL)
        return NULL;
        return NULL;
#endif
#endif
      memcpy (curr_prefix, curr_installdir, curr_prefix_len);
      memcpy (curr_prefix, curr_installdir, curr_prefix_len);
      curr_prefix[curr_prefix_len] = '\0';
      curr_prefix[curr_prefix_len] = '\0';
 
 
      return curr_prefix;
      return curr_prefix;
    }
    }
  }
  }
}
}
 
 
#if defined PIC && defined INSTALLDIR
#if defined PIC && defined INSTALLDIR
 
 
/* Full pathname of shared library, or NULL.  */
/* Full pathname of shared library, or NULL.  */
static char *shared_library_fullname;
static char *shared_library_fullname;
 
 
#if defined _WIN32 || defined __WIN32__
#if defined _WIN32 || defined __WIN32__
 
 
/* Determine the full pathname of the shared library when it is loaded.  */
/* Determine the full pathname of the shared library when it is loaded.  */
 
 
BOOL WINAPI
BOOL WINAPI
DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
DllMain (HINSTANCE module_handle, DWORD event, LPVOID reserved)
{
{
  (void) reserved;
  (void) reserved;
 
 
  if (event == DLL_PROCESS_ATTACH)
  if (event == DLL_PROCESS_ATTACH)
    {
    {
      /* The DLL is being loaded into an application's address range.  */
      /* The DLL is being loaded into an application's address range.  */
      static char location[MAX_PATH];
      static char location[MAX_PATH];
 
 
      if (!GetModuleFileName (module_handle, location, sizeof (location)))
      if (!GetModuleFileName (module_handle, location, sizeof (location)))
        /* Shouldn't happen.  */
        /* Shouldn't happen.  */
        return FALSE;
        return FALSE;
 
 
      if (!IS_PATH_WITH_DIR (location))
      if (!IS_PATH_WITH_DIR (location))
        /* Shouldn't happen.  */
        /* Shouldn't happen.  */
        return FALSE;
        return FALSE;
 
 
      shared_library_fullname = strdup (location);
      shared_library_fullname = strdup (location);
    }
    }
 
 
  return TRUE;
  return TRUE;
}
}
 
 
#else /* Unix */
#else /* Unix */
 
 
static void
static void
find_shared_library_fullname ()
find_shared_library_fullname ()
{
{
#ifdef __linux__
#ifdef __linux__
  FILE *fp;
  FILE *fp;
 
 
  /* Open the current process' maps file.  It describes one VMA per line.  */
  /* Open the current process' maps file.  It describes one VMA per line.  */
  fp = fopen ("/proc/self/maps", "r");
  fp = fopen ("/proc/self/maps", "r");
  if (fp)
  if (fp)
    {
    {
      unsigned long address = (unsigned long) &find_shared_library_fullname;
      unsigned long address = (unsigned long) &find_shared_library_fullname;
      for (;;)
      for (;;)
        {
        {
          unsigned long start, end;
          unsigned long start, end;
          int c;
          int c;
 
 
          if (fscanf (fp, "%lx-%lx", &start, &end) != 2)
          if (fscanf (fp, "%lx-%lx", &start, &end) != 2)
            break;
            break;
          if (address >= start && address <= end - 1)
          if (address >= start && address <= end - 1)
            {
            {
              /* Found it.  Now see if this line contains a filename.  */
              /* Found it.  Now see if this line contains a filename.  */
              while (c = getc (fp), c != EOF && c != '\n' && c != '/')
              while (c = getc (fp), c != EOF && c != '\n' && c != '/')
                continue;
                continue;
              if (c == '/')
              if (c == '/')
                {
                {
                  size_t size;
                  size_t size;
                  int len;
                  int len;
 
 
                  ungetc (c, fp);
                  ungetc (c, fp);
                  shared_library_fullname = NULL; size = 0;
                  shared_library_fullname = NULL; size = 0;
                  len = getline (&shared_library_fullname, &size, fp);
                  len = getline (&shared_library_fullname, &size, fp);
                  if (len >= 0)
                  if (len >= 0)
                    {
                    {
                      /* Success: filled shared_library_fullname.  */
                      /* Success: filled shared_library_fullname.  */
                      if (len > 0 && shared_library_fullname[len - 1] == '\n')
                      if (len > 0 && shared_library_fullname[len - 1] == '\n')
                        shared_library_fullname[len - 1] = '\0';
                        shared_library_fullname[len - 1] = '\0';
                    }
                    }
                }
                }
              break;
              break;
            }
            }
          while (c = getc (fp), c != EOF && c != '\n')
          while (c = getc (fp), c != EOF && c != '\n')
            continue;
            continue;
        }
        }
      fclose (fp);
      fclose (fp);
    }
    }
#endif
#endif
}
}
 
 
#endif /* WIN32 / Unix */
#endif /* WIN32 / Unix */
 
 
/* Return the full pathname of the current shared library.
/* Return the full pathname of the current shared library.
   Return NULL if unknown.
   Return NULL if unknown.
   Guaranteed to work only on Linux and Woe32.  */
   Guaranteed to work only on Linux and Woe32.  */
static char *
static char *
get_shared_library_fullname ()
get_shared_library_fullname ()
{
{
#if !(defined _WIN32 || defined __WIN32__)
#if !(defined _WIN32 || defined __WIN32__)
  static bool tried_find_shared_library_fullname;
  static bool tried_find_shared_library_fullname;
  if (!tried_find_shared_library_fullname)
  if (!tried_find_shared_library_fullname)
    {
    {
      find_shared_library_fullname ();
      find_shared_library_fullname ();
      tried_find_shared_library_fullname = true;
      tried_find_shared_library_fullname = true;
    }
    }
#endif
#endif
  return shared_library_fullname;
  return shared_library_fullname;
}
}
 
 
#endif /* PIC */
#endif /* PIC */
 
 
/* Returns the pathname, relocated according to the current installation
/* Returns the pathname, relocated according to the current installation
   directory.  */
   directory.  */
const char *
const char *
relocate (const char *pathname)
relocate (const char *pathname)
{
{
#if defined PIC && defined INSTALLDIR
#if defined PIC && defined INSTALLDIR
  static int initialized;
  static int initialized;
 
 
  /* Initialization code for a shared library.  */
  /* Initialization code for a shared library.  */
  if (!initialized)
  if (!initialized)
    {
    {
      /* At this point, orig_prefix and curr_prefix likely have already been
      /* At this point, orig_prefix and curr_prefix likely have already been
         set through the main program's set_program_name_and_installdir
         set through the main program's set_program_name_and_installdir
         function.  This is sufficient in the case that the library has
         function.  This is sufficient in the case that the library has
         initially been installed in the same orig_prefix.  But we can do
         initially been installed in the same orig_prefix.  But we can do
         better, to also cover the cases that 1. it has been installed
         better, to also cover the cases that 1. it has been installed
         in a different prefix before being moved to orig_prefix and (later)
         in a different prefix before being moved to orig_prefix and (later)
         to curr_prefix, 2. unlike the program, it has not moved away from
         to curr_prefix, 2. unlike the program, it has not moved away from
         orig_prefix.  */
         orig_prefix.  */
      const char *orig_installprefix = INSTALLPREFIX;
      const char *orig_installprefix = INSTALLPREFIX;
      const char *orig_installdir = INSTALLDIR;
      const char *orig_installdir = INSTALLDIR;
      const char *curr_prefix_better;
      const char *curr_prefix_better;
 
 
      curr_prefix_better =
      curr_prefix_better =
        compute_curr_prefix (orig_installprefix, orig_installdir,
        compute_curr_prefix (orig_installprefix, orig_installdir,
                             get_shared_library_fullname ());
                             get_shared_library_fullname ());
      if (curr_prefix_better == NULL)
      if (curr_prefix_better == NULL)
        curr_prefix_better = curr_prefix;
        curr_prefix_better = curr_prefix;
 
 
      set_relocation_prefix (orig_installprefix, curr_prefix_better);
      set_relocation_prefix (orig_installprefix, curr_prefix_better);
 
 
      initialized = 1;
      initialized = 1;
    }
    }
#endif
#endif
 
 
  /* Note: It is not necessary to perform case insensitive comparison here,
  /* Note: It is not necessary to perform case insensitive comparison here,
     even for DOS-like filesystems, because the pathname argument was
     even for DOS-like filesystems, because the pathname argument was
     typically created from the same Makefile variable as orig_prefix came
     typically created from the same Makefile variable as orig_prefix came
     from.  */
     from.  */
  if (orig_prefix != NULL && curr_prefix != NULL
  if (orig_prefix != NULL && curr_prefix != NULL
      && strncmp (pathname, orig_prefix, orig_prefix_len) == 0)
      && strncmp (pathname, orig_prefix, orig_prefix_len) == 0)
    {
    {
      if (pathname[orig_prefix_len] == '\0')
      if (pathname[orig_prefix_len] == '\0')
        /* pathname equals orig_prefix.  */
        /* pathname equals orig_prefix.  */
        return curr_prefix;
        return curr_prefix;
      if (ISSLASH (pathname[orig_prefix_len]))
      if (ISSLASH (pathname[orig_prefix_len]))
        {
        {
          /* pathname starts with orig_prefix.  */
          /* pathname starts with orig_prefix.  */
          const char *pathname_tail = &pathname[orig_prefix_len];
          const char *pathname_tail = &pathname[orig_prefix_len];
          char *result =
          char *result =
            (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1);
            (char *) xmalloc (curr_prefix_len + strlen (pathname_tail) + 1);
 
 
#ifdef NO_XMALLOC
#ifdef NO_XMALLOC
          if (result != NULL)
          if (result != NULL)
#endif
#endif
            {
            {
              memcpy (result, curr_prefix, curr_prefix_len);
              memcpy (result, curr_prefix, curr_prefix_len);
              strcpy (result + curr_prefix_len, pathname_tail);
              strcpy (result + curr_prefix_len, pathname_tail);
              return result;
              return result;
            }
            }
        }
        }
    }
    }
  /* Nothing to relocate.  */
  /* Nothing to relocate.  */
  return pathname;
  return pathname;
}
}
 
 
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.