Pelles C forum

Pelles C => Bug reports => Topic started by: frankie on May 26, 2019, 03:59:13 PM

Title: _popen 64bits broken implementation
Post by: frankie on May 26, 2019, 03:59:13 PM
The implementation of the function _popen, 64bits version, is broken.
See this post (https://forum.pellesc.de/index.php?topic=7973.msg29412#msg29412).
The 32bits version works.
Title: Re: _popen 64bits broken implementation
Post by: TimoVJL on May 26, 2019, 04:37:34 PM
MS example fails too, crash in x64
Code: [Select]
// crt_popen.c
/* This program uses _popen and _pclose to receive a
* stream of text from a system process.
*/

#include <stdio.h>
#include <stdlib.h>

int main( void )
{
   char   psBuffer[128];
   FILE   *pPipe;

        /* Run DIR so that it writes its output to a pipe. Open this
         * pipe with read text attribute so that we can read it
         * like a text file.
         */

//   if( (pPipe = _popen( "dir *.c /on /p", "rt" )) == NULL )
   if( (pPipe = _popen( "dir *.c /on /p", "r" )) == NULL )
      exit( 1 );

   /* Read pipe until end of file, or an error occurs. */

   while(fgets(psBuffer, 128, pPipe))
   {
      printf(psBuffer);
   }

   /* Close pipe and print return value of pPipe. */
   if (feof( pPipe))
   {
     printf( "\nProcess returned %d\n", _pclose( pPipe ) );
   }
   else
   {
     printf( "Error: Failed to read the pipe to the end.\n");
   }
}