Changeset 3df5b10 in git for omalloc/omFindExec.c


Ignore:
Timestamp:
Aug 14, 2000, 2:08:48 PM (24 years ago)
Author:
Olaf Bachmann <obachman@…>
Branches:
(u'fieker-DuVal', '117eb8c30fc9e991c4decca4832b1d19036c4c65')(u'spielwiese', '38dfc5131670d387a89455159ed1e071997eec94')
Children:
9d605984360cf5d30bdf13e295d63c41ae1bc952
Parents:
ecf4ca6ad75f235385946daeae249f3bc6fd13c8
Message:
* update


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

Legend:

Unmodified
Added
Removed
  • omalloc/omFindExec.c

    recf4ca6 r3df5b10  
    44 *  Author:  obachman (Olaf Bachmann)
    55 *  Created: 11/99
    6  *  Version: $Id: omFindExec.c,v 1.2 2000-05-31 13:34:31 obachman Exp $
     6 *  Version: $Id: omFindExec.c,v 1.3 2000-08-14 12:08:45 obachman Exp $
    77 *******************************************************************/
    88
     
    2020#define MAXPATHLEN 1024
    2121#endif
    22 
    2322
    2423/* ABSOLUTE_FILENAME_P (fname): True if fname is an absolute filename */
     
    3635char * omFindExec (const char *name, char* executable)
    3736#else
    38 char * omFindExec_link (const char *name, char* executable)
     37static char * omFindExec_link (const char *name, char* executable)
    3938#endif
    4039{
    4140  char *search;
    4241  char *p;
     42#ifdef WINNT
     43  char *extra = NULL;
     44#endif
    4345  char tbuf[MAXPATHLEN];
    4446
     
    8486      char *extra = NULL;
    8587      /* we are under msdos display */
    86       FIX ME
    87         extra = (char*) AllocL((search != NULL ? strlen(search) : 0) + 3);
     88      extra = (char*) omAlloc((search != NULL ? strlen(search) : 0) + 3);
    8889      strcpy(extra, ".:");
    8990      if (search != NULL) strcat(extra, search);
     
    125126#ifdef WINNT
    126127          if (extra != NULL)
    127             FreeL(extra);
     128            omFree(extra);
    128129#endif
    129130          strcpy(executable, tbuf);
     
    142143    }
    143144  }
    144    
    145     return NULL;
    146   }
     145  return NULL;
     146}
    147147
    148148#ifdef HAVE_READLINK
     149/* similar to readlink, but dont' mess up absolute pathnames */
     150static int my_readlink(const char* name, char* buf, size_t bufsize)
     151{
     152  char buf2[MAXPATHLEN];
     153  int ret;
     154 
     155  if ((ret = readlink(name, buf2, bufsize)) > 0)
     156  {
     157    buf2[ret] = 0;
     158    if (*name == '/' && *buf2 != '/')
     159    {
     160      char* last = strrchr(name, '/');
     161      int i = 0;
     162      while (&(name[i]) != last)
     163      {
     164        buf[i] = name[i];
     165        i++;
     166      }
     167      buf[i] = '/';
     168      i++;
     169      strcpy(&(buf[i]), buf2);
     170      return i + ret;
     171    }
     172    else
     173    {
     174      strcpy(buf, buf2);
     175    }
     176  }
     177  return ret;
     178}
    149179
    150180#define MAX_LINK_LEVEL 10
     
    152182   followed up to MAX_LINK_LEVEL
    153183*/
    154 int full_readlink(const char* name, char* buf, size_t bufsize)
     184static int full_readlink(const char* name, char* buf, size_t bufsize)
    155185{
    156186  int ret;
    157187 
    158   if ((ret=readlink(name, buf, bufsize)) > 0)
     188  if ((ret=my_readlink(name, buf, bufsize)) > 0)
    159189  {
    160190    char buf2[MAXPATHLEN];
     
    164194    {
    165195      buf[ret] = '\0';
    166       if ((ret2 = readlink(buf, buf2, MAXPATHLEN)) > 0)
     196      if ((ret2 = my_readlink(buf, buf2, MAXPATHLEN)) > 0)
    167197      {
    168198        i++;
     
    195225  if (link != NULL && (ret=full_readlink(link, buf, MAXPATHLEN)) > 0)
    196226  {
     227    char *p = strrchr(link, '/');
     228
     229
     230    if(p!=NULL) *(p+1)='\0';
    197231    buf[ret]='\0';
    198     return omFindExec_link(buf, exec);
     232
     233    if (buf[0] != '/')
     234    {
     235      strcpy(exec, link);
     236      strcat(exec, buf);
     237    }
     238    else
     239    {
     240      strcpy(exec, buf);
     241    }
     242
     243    return exec;
    199244  }
    200245  return link;
Note: See TracChangeset for help on using the changeset viewer.