NO

Author Topic: _popen 64bits broken implementation  (Read 2127 times)

Offline frankie

  • Global Moderator
  • Member
  • *****
  • Posts: 2113
_popen 64bits broken implementation
« on: May 26, 2019, 03:59:13 PM »
The implementation of the function _popen, 64bits version, is broken.
See this post.
The 32bits version works.
« Last Edit: May 26, 2019, 05:28:52 PM by frankie »
"It is better to be hated for what you are than to be loved for what you are not." - Andre Gide

Offline TimoVJL

  • Global Moderator
  • Member
  • *****
  • Posts: 2107
Re: _popen 64bits broken implementation
« Reply #1 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");
   }
}
May the source be with you