delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/11/25/12:02:30

Date: Tue, 25 Nov 1997 19:00:12 +0200 (IST)
From: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
To: DJ Delorie <dj AT delorie DOT com>
cc: djgpp-workers AT delorie DOT com
Subject: Changes in dosexec.c to support foo.bar.exe
Message-ID: <Pine.SUN.3.91.971125185513.29142C-100000@is>
MIME-Version: 1.0

These changes make `spawnXX' and `system' find and invoke programs whose
basename has two or more dots (under LFN only).  Note that this has a
side-effect (which is IMHO The Right Thing) of calling foo.exe if both foo
and foo.exe are present (i.e., the .exe will be invoked instead of the raw
COFF image). 

I also corrected a bug whereby invoking `foo' would try to ``run'' a 
directory `foo' (or `foo.exe' etc.) if there were one.  Now this should 
continue looking for `foo' with other extensions, and set errno to EISDIR 
if none is found.

diff -c src/libc/dos/process/dosexec.c~0 src/libc/dos/process/dosexec.c
*** src/libc/dos/process/dosexec.c~0	Fri Oct 10 01:37:06 1997
--- src/libc/dos/process/dosexec.c	Tue Nov 25 18:45:16 1997
***************
*** 930,944 ****
      }
    }
  
!   if (hasdot)
!   {
!     if (access(buf, 0) == 0 && access(buf, D_OK))
!     {
!       errno = e;
!       return buf;
!     }
!   }
!   else
      for (i=0; interpreters[i].extension; i++)
      {
        strcpy(rp, interpreters[i].extension);
--- 930,937 ----
      }
    }
  
!   /* Under LFN, we must try the extensions even if PROGRAM already has one.  */
!   if (!hasdot || _use_lfn(program))
      for (i=0; interpreters[i].extension; i++)
      {
        strcpy(rp, interpreters[i].extension);
***************
*** 953,958 ****
--- 946,957 ----
        }
      }
  
+   if (access(buf, 0) == 0 && access(buf, D_OK))
+   {
+     errno = e;
+     return buf;
+   }
+ 
    if (haspath || !envp)
      return 0;
    *rp = 0;
***************
*** 985,1000 ****
        *rp++ = *ptr;
      *rp = 0;
      
!     if (hasdot)
!     {
!       if (access(buf, 0) == 0 && access(buf, D_OK))
!       {
! 	errno = e;
! 	return buf;
!       }
!     }
!     else
!     {
        for (i=0; interpreters[i].extension; i++)
        {
          strcpy(rp, interpreters[i].extension);
--- 984,990 ----
        *rp++ = *ptr;
      *rp = 0;
      
!     if (!hasdot || _use_lfn(buf))
        for (i=0; interpreters[i].extension; i++)
        {
          strcpy(rp, interpreters[i].extension);
***************
*** 1004,1009 ****
--- 994,1003 ----
            return buf;
  	}
        }
+     if (access(buf, 0) == 0 && access(buf, D_OK))
+     {
+       errno = e;
+       return buf;
      }
      if (*pe == 0)
        return 0;
***************
*** 1019,1024 ****
--- 1013,1020 ----
    char **envpp;
    char rpath[FILENAME_MAX], *rp, *rd=0;
    int e = errno;
+   int is_dir = 0;
+   int found = 0;
  
    if (path == 0 || argv[0] == 0)
    {
***************
*** 1043,1067 ****
        rd = 0;
    }
    *rp = 0;
!   if (rd)
    {
      for (i=0; interpreters[i].extension; i++)
!       if (stricmp(rd, interpreters[i].extension) == 0)
!         break;
    }
!   while (access(rpath, 0) && access(rpath, D_OK))
    {
!     i++;
!     if (interpreters[i].extension == 0 || rd)
      {
!       errno = ENOENT;
!       return -1;
      }
!     strcpy(rp, interpreters[i].extension);
    }
    errno = e;
-   if (i == -1)
-     i = INTERP_NO_EXT;
    i = interpreters[i].interp(rpath, argvp, envpp);
    if (mode == P_OVERLAY)
      exit(i);
--- 1039,1090 ----
        rd = 0;
    }
    *rp = 0;
! 
!   /* If LFN is supported on the volume where rpath resides, we
!      might have something like foo.bar.exe or even foo.exe.com.
!      If so, look for RPATH.ext before even trying RPATH itself. */
!   if (_use_lfn(rpath) || !rd)
    {
      for (i=0; interpreters[i].extension; i++)
!     {
!       strcpy(rp, interpreters[i].extension);
!       if (access(rpath, F_OK) == 0 && !(is_dir = (access(rpath, D_OK) == 0)))
!       {
! 	found = 1;
! 	break;
!       }
!     }
    }
! 
!   if (!found)
    {
!     const char *rpath_ext;
! 
!     if (rd)
      {
!       i = 0;
!       rpath_ext = rd;
      }
!     else
!     {
!       i = INTERP_NO_EXT;
!       rpath_ext = "";
!     }
!     for ( ; interpreters[i].extension; i++)
!       if (stricmp(rpath_ext, interpreters[i].extension) == 0
! 	  && access(rpath, F_OK) == 0
! 	  && !(is_dir = (access(rpath, D_OK) == 0)))
!       {
! 	found = 1;
!         break;
!       }
!   }
!   if (!found)
!   {
!     errno = is_dir ? EISDIR : ENOENT;
!     return -1;
    }
    errno = e;
    i = interpreters[i].interp(rpath, argvp, envpp);
    if (mode == P_OVERLAY)
      exit(i);

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019