delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp-workers/1997/06/30/05:09:36

Date: Mon, 30 Jun 1997 11:06:56 +0200 (MET DST)
From: Molnar Laszlo <molnarl AT ether>
To: djgpp-workers AT delorie DOT com
Subject: bug in popen.c
Message-ID: <Pine.SOL.3.95.970630105133.6357A-100000@dumballah.tvnet.hu>
MIME-Version: 1.0

Hi Workers!

Porting perl 5.004 to djgpp, I've found a bug in popen().
It's in its temporary file name handling. When a program that uses popen()
calls another djgpp program that uses popen too, the bug can appear,
because both program may use the same temporary files. 


Here is my patch: 

*** popen.c~	Wed Jun 12 23:44:36 1996
--- popen.c	Sat Jun 28 02:08:10 1997
***************
*** 74,82 ****
  popen (const char *cm, const char *md) /* program name, pipe mode */
  {
!   struct pipe_list *l1, *l2;
!   static char *tn = NULL;       /* temporary file basename */
  
!   if (!tn)
!     if ((tn = tmpnam(0)) == NULL)
        return NULL;
  
--- 74,81 ----
  popen (const char *cm, const char *md) /* program name, pipe mode */
  {
!   struct pipe_list *l1;
!   char *tn;
  
!   if ((tn = tmpnam(0)) == NULL)
        return NULL;
  
***************
*** 86,113 ****
  
    /* zero out elements to we'll get here */
-   l1->fd = 0;
    l1->fp = NULL;
    l1->next = NULL;
  
!   /* if empty list - just grab new node */
!   if (!pl)
!     pl = l1;
!   else
!   {
!     /* otherwise, find last node in list */
!     ++(l1->fd);
!     l2 = pl;
!     while (l2->next)
!     {
!       ++(l1->fd);
!       l2 = l2->next;
!     };
!     /* add new node to list */
!     l2->next = l1;
!   }
  
    /* stick in elements we know already */
    strcpy (l1->mode, md);
!   sprintf (l1->temp_name, "%s.%d", tn, l1->fd);
  
    /* if can save the program name, build temp file */
--- 85,98 ----
  
    /* zero out elements to we'll get here */
    l1->fp = NULL;
    l1->next = NULL;
  
!   if (pl!=NULL)
!     l1->next = pl;
!   pl = l1;
  
    /* stick in elements we know already */
    strcpy (l1->mode, md);
!   sprintf (l1->temp_name, "%s", tn);
  
    /* if can save the program name, build temp file */


- Raw text -


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