delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/02/08/17:38:52

From: "Mark E." <snowball3 AT bigfoot DOT com>
To: djgpp-workers AT delorie DOT com
Date: Thu, 8 Feb 2001 14:15:25 -0500
MIME-Version: 1.0
Subject: dosexec.c changes
Message-ID: <3A82A9FD.48.939B45@localhost>
X-mailer: Pegasus Mail for Win32 (v3.12c)
Reply-To: djgpp-workers AT delorie DOT com

Hello again,
This fixes several problems found in dosexec.c.
After executing a script, errno is always set after returning from spawn*. This 
happens because script_exec didn't restore errno after a successfull search for a 
file.

When LFN=N, a file without an executable extension wouldn't be found. It would 
however find a different file with the same name except that it had an executable 
extension.

And a typo was fixed.

Index: dosexec.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/dos/process/dosexec.c,v
retrieving revision 1.11
diff -c -p -r1.11 dosexec.c
*** dosexec.c	2000/12/25 20:33:24	1.11
--- dosexec.c	2001/02/08 19:03:19
*************** static int script_exec(const char *progr
*** 1087,1092 ****
--- 1087,1093 ----
    int has_extension = 0, has_drive = 0;
    char pinterp[FILENAME_MAX];
    int (*spawnfunc)(int, const char *, char *const [], char *const []);
+   int e = errno;
  
    f = fopen(program, "rt");
    if (!f)
*************** static int script_exec(const char *progr
*** 1150,1156 ****
--- 1151,1160 ----
    }
    else if (__dosexec_find_on_path(interp, (char **)0, pinterp)
  	   || __dosexec_find_on_path(base, envp, pinterp))
+   {
      spawnfunc = spawnve;	/* no need to search on PATH: we've found it */
+     errno = e;
+   }
    else
      return -1;
  
*************** static struct {
*** 1190,1202 ****
    { ".sed", script_exec, INTERP_FLAG_SKIP_SEARCH },  /* Sed */
    { "",     go32_exec, 0 },
    { 0,      script_exec, 0 },  /* every extension not mentioned above calls it */
!   { 0,      0 },
  };
  
  /* This is the index into the above array of the interpreter
     which is called when the program filename has no extension.  */
  #define INTERP_NO_EXT (sizeof(interpreters)/sizeof(interpreters[0]) - 3)
  
  /*-------------------------------------------------*/
  
  char *
--- 1194,1210 ----
    { ".sed", script_exec, INTERP_FLAG_SKIP_SEARCH },  /* Sed */
    { "",     go32_exec, 0 },
    { 0,      script_exec, 0 },  /* every extension not mentioned above calls it */
!   { 0,      0, 0 },
  };
  
  /* This is the index into the above array of the interpreter
     which is called when the program filename has no extension.  */
  #define INTERP_NO_EXT (sizeof(interpreters)/sizeof(interpreters[0]) - 3)
  
+ /* This is the index into the above array of the interpreter
+    which is called when the filename has none of the above extensions.  */
+ #define INTERP_OTHER_EXT (sizeof(interpreters)/sizeof(interpreters[0]) - 2)
+ 
  /*-------------------------------------------------*/
  
  char *
*************** int __spawnve(int mode, const char *path
*** 1359,1384 ****
    
    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)
    {
--- 1367,1375 ----
    
    if (!found)
    {
!     i = (rd) ? INTERP_OTHER_EXT : INTERP_NO_EXT;
!     if (access(rpath, F_OK) == 0 && !(is_dir = (access(rpath, D_OK) == 0)))
!       found = 1;
    }
    if (!found)
    {

- Raw text -


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