delorie.com/djgpp/bugs/show.cgi   search  
Bug 000273

When Created: 02/27/1999 11:00:42
Against DJGPP version: 2.02
By whom: John_B_Pratt@yahoo.com
Abstract: redirection to a lfn as parameter to system
When executing the following code:
    sprintf(cmd, "gzip -c -9 %s > %s", src, dest);
    system(cmd);

I got an error when dest had spaces in the file name.
I modified the code as follows:
    sprintf(cmd, "gzip -c -9 \"%s\" > \"%s\"", src, dest);
    system(cmd);

Which gave me the error "No such file or directory" error
in ALL cases.  I worked around the problem by clearing the
__system_redirect flag in __system_flags.

Workaround added: 02/27/1999 11:00:25
By whom: John_B_Pratt@yahoo.com
I worked around the problem by clearing the
__system_redirect flag in __system_flags.

Workaround added: 03/20/1999 19:00:00
By whom: John_B_Pratt@yahoo.com
You can clear redirection like this:

	sprintf(cmd, "gzip -c -%d \"%s\" > \"%s\"", 
		mediaInfo->compressionLevel,
		srcPath, 
		destPath);

	{
	    int savedFlags = __system_flags;

	    __system_flags &= ~__system_redirect;
	    system(cmd);
	    __system_flags = savedFlags;
	}


Or get rid of redirection on the command line and redirect stdout like this:
      /* dup stdout */
      if ((l1->fd = dup (fileno (stdout))) == EOF)
	l1->fp = NULL;
      else if (!(l1->fp = freopen (l1->temp_name, "wb", stdout)))
	l1->fp = NULL;
      else
	/* exec cmd */
	if ((l1->exit_status = system (cm)) == EOF)
	  l1->fp = NULL;
      /* reopen real stdout */
      if (dup2 (l1->fd, fileno (stdout)) == EOF)
	l1->fp = NULL;

Solution added: 04/19/1999 06:00:10
By whom: eliz@is.elta.co.il
This is indeed a bug: `system' did not remove quotes from the target
of redirection.

This bug is corrected in WIP and will be in v2.03.

Here's a patch:

*** src/libc/ansi/stdlib/system.c~0     Sun Jun 28 23:21:40 1998                
--- src/libc/ansi/stdlib/system.c       Sun Apr 18 22:17:08 1999                
*************** system (const char *cmdline)                                    
*** 654,661 ****                                                                
            errno = EINVAL;                                                     
            goto leave;                                                         
          }                                                                     
!         *fp = memcpy ((char *)alloca (v - u + 1), u, v - u);                  
!         (*fp)[v - u] = 0;                                                     
          strcpy (t, v);                                                        
          again = 1;                                                            
          break;                                                                
--- 654,662 ----                                                                
            errno = EINVAL;                                                     
            goto leave;                                                         
          }                                                                     
!         /* The target of redirection might be quoted, so we need to           
!            unquote it.  */                                                    
!         *fp = __unquote ((char *)alloca (v - u + 1), u, v);                   
          strcpy (t, v);                                                        
          again = 1;                                                            
          break;

Fixed in version on 04/22/1999 09:00:26
By whom: eliz@is.elta.co.il



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