Changeset ea35599 in git


Ignore:
Timestamp:
May 20, 1998, 6:23:49 PM (26 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'spielwiese', 'fe61d9c35bf7c61f2b6cbf1b56e25e2f08d536cc')
Children:
c052d0e90b6b3a3f99f5c70b1e90b6d8f020865e
Parents:
651b4646ed535e81739179b38258acc14067c72b
Message:
* fixed following symbolic links


git-svn-id: file:///usr/local/Singular/svn/trunk@1953 2c84dea3-7e68-4137-9b89-c4e89433aadc
File:
1 edited

Legend:

Unmodified
Added
Removed
  • Singular/find_exec.c

    r651b46 rea35599  
    5151   searches the directories in the PATH environment variable if PROG
    5252   has no directory components. */
    53 char *
    54 find_executable (const char *name)
     53#ifndef HAVE_READLINK
     54char * find_executable (const char *name)
     55#else
     56char * find_executable_link (const char *name)
     57#endif
    5558{
    5659  char *search;
     
    6063
    6164  if (ABSOLUTE_FILENAME_P(name)) {
    62       /* If we can execute the named file, and it is normal, then return it. */
    63       if (! access (name, X_OK)) {
    64         struct stat stat_temp;
    65         char buf[MAXPATHLEN];
    66         int ret;
    67 
    68         if (stat (name, &stat_temp))
    69           return 0;
    70 
    71 #ifdef HAVE_READLINK
    72         if( (ret=readlink(name, buf, MAXPATHLEN))>0) {
    73           char *p = strrchr(name, '/');
    74           if(p!=NULL) *(p+1)='\0';
    75           buf[ret]='\0';
    76           if(buf[0]=='/') return(find_executable(buf));
    77           strcat(name, buf);
    78           return(find_executable(name));
    79         }
    80 #endif /* HAVE_READLINK */
    81 #ifndef STAT_MACROS_BROKEN
    82         if (! S_ISREG(stat_temp.st_mode))
    83           return 0;
    84 #endif
    85        
     65      /* If we can execute the named file then return it. */
     66      if (! access (name, X_OK))
    8667        return copy_of (name);
    87       }
    8868    }
    8969  else {
     
    185165      strcat (tbuf, name);
    186166
    187       /* If we can execute the named file, and it is normal, then return it. */
     167      /* If we can execute the named file, then return it. */
    188168      if (! access (tbuf, X_OK)) {
    189         struct stat stat_temp;
    190         char buf[MAXPATHLEN];
    191         int ret;
    192 
    193         if (stat (tbuf, &stat_temp))
    194           continue;
    195 
    196 #ifdef HAVE_READLINK
    197         if( (ret=readlink(tbuf, buf, MAXPATHLEN))>0) {
    198           char *p = strrchr(tbuf, '/');
    199           if(p!=NULL) *(p+1)='\0';
    200           buf[ret]='\0';
    201           if(buf[0]=='/') return(find_executable(buf));
    202           strcat(tbuf, buf);
    203           return(find_executable(tbuf));
    204         }
    205 #endif /* HAVE_READLINK */
    206 #ifndef STAT_MACROS_BROKEN
    207         if (! S_ISREG(stat_temp.st_mode))
    208           continue;
    209 #endif
    210169#ifdef WINNT
    211170        if (extra != NULL)
     
    219178  return NULL;
    220179}
     180
     181#ifdef HAVE_READLINK
     182char * find_executable (const char *name)
     183{
     184  char * link = find_executable_link(name);
     185  char buf[MAXPATHLEN];
     186  int ret;
     187
     188  if (link == NULL && (ret=readlink(name, buf, MAXPATHLEN)) > 0)
     189  {
     190    buf[ret] ='\0';
     191    link = find_executable_link(buf);
     192  }
     193  // follow, if we have a link
     194  if (link != NULL && (ret=readlink(link, buf, MAXPATHLEN)) > 0)
     195  {
     196    char *p = strrchr(link, '/');
     197    char *executable;
     198
     199   
     200    if(p!=NULL) *(p+1)='\0';
     201    buf[ret]='\0';
     202   
     203    if (buf[0] != '/')
     204    {
     205      executable = (char*) AllocL(strlen(link) + ret);
     206      strcpy(executable, link);
     207      strcat(executable, buf);
     208    }
     209    else
     210    {
     211      executable = copy_of(buf);
     212    }
     213   
     214    FreeL(link);
     215    return executable;
     216  }
     217  return link;
     218}
     219#endif /* HAVE_READLINK */
    221220
    222221#else
Note: See TracChangeset for help on using the changeset viewer.