delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/2001/04/05/23:43:26

From: "Mark E." <snowball3 AT bigfoot DOT com>
To: djgpp-workers AT delorie DOT com
Date: Thu, 5 Apr 2001 23:43:29 -0400
MIME-Version: 1.0
Subject: system() and SHELL patch
Message-ID: <3ACD0321.18747.214DE3@localhost>
X-mailer: Pegasus Mail for Win32 (v3.12c)
Reply-To: djgpp-workers AT delorie DOT com

This patch treats the SHELL variable like __spawnve treats a file starting 
with "#! /bin/sh": if an executable extension can't be added, then PATH is 
searched. I noticed that the command processor is figured out both in system 
and _shell_command. This seems unneccessary, but I did nothing about it since 
there may be a valid reason for doing it twice.

Index: system.c
===================================================================
RCS file: /cvs/djgpp/djgpp/src/libc/ansi/stdlib/system.c,v
retrieving revision 1.8
diff -c -p -r1.8 system.c
*** system.c	2000/12/25 20:31:51	1.8
--- system.c	2001/04/05 21:40:03
*************** _shell_command (const char *prog, const 
*** 71,77 ****
  {
    char *comspec = getenv ("COMSPEC");
    char *shell = 0;
! 
    if (!prog)
      prog = "";
    if (!cmdline)
--- 71,78 ----
  {
    char *comspec = getenv ("COMSPEC");
    char *shell = 0;
!   char unixy_shell[FILENAME_MAX];
!   
    if (!prog)
      prog = "";
    if (!cmdline)
*************** _shell_command (const char *prog, const 
*** 79,85 ****
  
    if (sys_flags & __system_use_shell)
      shell = getenv ("SHELL");
!   if (!shell)
      shell = comspec;
    /* Is it worth the hassle to get the boot drive (Int 21h/AX=3305h)
       and look for COMMAND.COM there if COMSPEC fails?  */
--- 80,111 ----
  
    if (sys_flags & __system_use_shell)
      shell = getenv ("SHELL");
!   /* The shell name may be in the form of a Unix-style path like "/bin/sh".
!      Try adding executable extensions or searching for the basename along
!      the PATH. */
!   if (shell)
!   {
!     int has_extension = 0;
!     char *base, *ptr;
!     for (base = ptr = shell; *ptr; ptr++)
!     {
!       if (*ptr == '.')
!         has_extension = 1;
!       if (*ptr == '/' || *ptr == '\\' || *ptr == ':')
!       {
!         has_extension = 0;
!         base = ptr + 1;
!       }
!     }
!   
!     if (!has_extension)
!     {
!       if (__dosexec_find_on_path(shell, 0, unixy_shell)
!           || __dosexec_find_on_path(base, environ, unixy_shell))
!         shell = unixy_shell;
!     }
!   }
!   else
      shell = comspec;
    /* Is it worth the hassle to get the boot drive (Int 21h/AX=3305h)
       and look for COMMAND.COM there if COMSPEC fails?  */
*************** system (const char *cmdline)
*** 540,546 ****
    const char *comspec  = getenv ("COMSPEC");
    const char *shell    = 0;
    int call_shell;
! 
    sys_flags = __system_flags;
    if (envflags && *envflags)
    {
--- 566,573 ----
    const char *comspec  = getenv ("COMSPEC");
    const char *shell    = 0;
    int call_shell;
!   char unixy_shell[FILENAME_MAX];
!   
    sys_flags = __system_flags;
    if (envflags && *envflags)
    {
*************** system (const char *cmdline)
*** 553,559 ****
  
    if (sys_flags & __system_use_shell)
      shell = getenv ("SHELL");
!   if (!shell)
      shell = comspec;
    if (!shell)
      shell = command_com;
--- 580,611 ----
  
    if (sys_flags & __system_use_shell)
      shell = getenv ("SHELL");
!   /* The shell name may be in the form of a Unix-style path like "/bin/sh".
!      Try adding executable extensions or searching for the basename along
!      the PATH. */
!   if (shell)
!   {
!     int has_extension = 0;
!     char *base, *ptr;
!     for (base = ptr = (char *)shell; *ptr; ptr++)
!     {
!       if (*ptr == '.')
!         has_extension = 1;
!       if (*ptr == '/' || *ptr == '\\' || *ptr == ':')
!       {
!         has_extension = 0;
!         base = ptr + 1;
!       }
!     }
!   
!     if (!has_extension)
!     {
!       if (__dosexec_find_on_path(shell, 0, unixy_shell)
!           || __dosexec_find_on_path(base, environ, unixy_shell))
!         shell = unixy_shell;
!     }
!   }
!   else
      shell = comspec;
    if (!shell)
      shell = command_com;

- Raw text -


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