www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/02/20/19:28:37

Message-ID: <330D133E.77@cs.com>
Date: Thu, 20 Feb 1997 19:15:11 -0800
From: "John M. Aldrich" <fighteer AT cs DOT com>
Reply-To: fighteer AT cs DOT com
Organization: Two pounds of chaos and a pinch of salt
MIME-Version: 1.0
To: Eli Zaretskii <eliz AT is DOT elta DOT co DOT il>
CC: DJGPP Workers Mailing List <djgpp-workers AT delorie DOT com>,
"Vyacheslav O. Myskin" <V DOT O DOT Myskin AT inp DOT nsk DOT su>, djgpp AT delorie DOT com
Subject: Re: Starnge rm behavour
References: <Pine DOT SUN DOT 3 DOT 91 DOT 970220091021 DOT 25071M-100000 AT is>

This is a multi-part message in MIME format.

--------------71FF3B8D538C
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Eli Zaretskii wrote:
> 
> And btw, I think `redir' should be built with transfer buffer of 64K, so
> that it never fails a program due to insufficient space there.  If
> `redir' has 64K transfer buffer, you can just malloc a 64K-long buffer
> and never bother to realloc.

Okay.  Here's try #2.  :)

I changed the command line to malloc 16k and realloc more if it runs out
of room.  I also changed the makefile in src/utils to automatically
stubedit redir.exe with a 64k transfer buffer.

The attached patch is based on the _original_ redir.c, not the one I
submitted previously.  All usage instructions are the same except that
this time the patch should be run from the root djgpp directory instead
of from src/utils.  

Hope this helps!

-- 
---------------------------------------------------------------------
| John M. Aldrich, aka Fighteer I |        fighteer AT cs DOT com          |
| Proud owner of what might one   |   http://www.cs.com/fighteer    |
| day be a spectacular MUD...     | Plan: To make Bill Gates suffer |
---------------------------------------------------------------------

--------------71FF3B8D538C
Content-Type: text/plain; charset=us-ascii; name="REDIR2.DIF"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="REDIR2.DIF"

*** src/utils/redir.c~0	Wed Jul 12 04:06:50 1995
--- src/utils/redir.c	Thu Feb 20 19:01:58 1997
***************
*** 46,52 ****
  {
    /*               ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 */
    fprintf(stderr, "Redir 1.0 Copyright (C) 1995 DJ Delorie (dj AT delorie DOT com) - distribute freely\n");
!   fprintf(stderr, "NO WARRANTEE.  This program is protected by the GNU General Public License.\n");
    fprintf(stderr, "Usage: redir [-i file] [-o file] [-oa file] [-e file] [-ea file]\n");
    fprintf(stderr, "                [-eo] [-oe] [-x] [-t] command [args . . .]\n\n");
    fprintf(stderr, "  -i file   redirect stdandard input from file\n");
--- 46,52 ----
  {
    /*               ----+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 */
    fprintf(stderr, "Redir 1.0 Copyright (C) 1995 DJ Delorie (dj AT delorie DOT com) - distribute freely\n");
!   fprintf(stderr, "NO WARRANTY.  This program is protected by the GNU General Public License.\n");
    fprintf(stderr, "Usage: redir [-i file] [-o file] [-oa file] [-e file] [-ea file]\n");
    fprintf(stderr, "                [-eo] [-oe] [-x] [-t] command [args . . .]\n\n");
    fprintf(stderr, "  -i file   redirect stdandard input from file\n");
***************
*** 74,79 ****
--- 74,82 ----
  int
  main(int argc, char **argv)
  {
+   char *cmdline;  /* hold command line to pass to system() */
+   size_t sz;      /* size of allocation for cmdline */
+   int i;          /* arg counter */
  
    if (argc < 2)
      usage();
***************
*** 151,157 ****
      argv++;
    }
  
!   rv = spawnvp(P_WAIT, argv[1], argv+1);
    if (rv < 0)
      fatal("Error attempting to run program %s\n", argv[1]);
  
--- 154,188 ----
      argv++;
    }
  
!   /* The old method of calling spawnvp() breaks v2.01 programs that use
!    * wildcards.  To fix this, build the remaining arguments into one long
!    * string to pass to system().
!    */
!   sz = 16384;   /* initial malloc size */
!   if ((cmdline = malloc(sz)) == NULL)
!   {
!     fprintf(std_err, "redir: malloc failed for %lu bytes", sz);
!     exit(1);
!   }
!   *cmdline = '\0';
!   for (i = 1; i < argc; i++)
!   {
!     if (strlen(cmdline) + strlen(argv[i]) + 1 > sz)
!     {
!       sz += 16384;   /* malloc increment */
!       if ((cmdline = realloc(cmdline,sz)) == NULL)
!       {
! 	fprintf(std_err, "redir: realloc failed for %lu bytes", sz);
! 	exit(1);
!       }
!     }
!     strcat(cmdline, argv[i]);
!     if (i < argc - 1)
! 	strcat(cmdline, " ");
!   }
!   rv = system(cmdline);
!   free(cmdline);
!   
    if (rv < 0)
      fatal("Error attempting to run program %s\n", argv[1]);
  
*** src/utils/makefile.~	Tue Jan 23 22:15:58 1996
--- src/utils/makefile	Thu Feb 20 19:02:46 1997
***************
*** 21,26 ****
--- 21,31 ----
  
  include $(TOP)/../makefile.prg
  
+ $(BIN)/redir.exe : $C redir.o $L
+ 	$(LINK)
+ 	$(EXE)
+ 	$(BIN)/stubedit $(BIN)/redir.exe bufsize=64k
+ 
  $(BIN)/rem.com : rem.asm
  	djasm $^ $@
  

--------------71FF3B8D538C--

- Raw text -


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