PRB: freopen() Function Fails in QuickWin Libraries

ID: Q76664

7.00 | 1.00 1.50 MS-DOS | WINDOWS kbprg kbprb

The information in this article applies to:

SYMPTOMS

The freopen() function in the Microsoft C run-time library fails if an application attempts to reassign stdin, stdout, or stderr in a QuickWin window. The sample code below demonstrates this behavior.

CAUSE

This limitation is caused by a design restriction in the QuickWin implementation. QuickWin does not supporting stdin, stdout, or stderr (unlike MS-DOS and OS/2). Because QuickWin assigns all three standard streams to the same file handle, closing one stream affects the others. In MS-DOS and OS/2, each stream has its own file handle that the application can manipulate without affecting the other streams.

RESOLUTION

Do not reassign stdin, stdout, or stderr while in a QuickWin window.

MORE INFORMATION

Sample Code

/* Compile options needed: QuickWin EXE
*/ 

#include <stdio.h>
#include <process.h>

FILE *stream, *errstream;

void main(void)
{
   /* Reassign "stdout" to "data2" */ 
   stream = freopen("data2", "w", stdout);

   if (stream == NULL )              /* If reassignment failed */ 
      printf("error on freopen\n");
   else
   {
      fprintf(stream,"This will go to the file `data2'\n");
      printf("`stdout' successfully reassigned\n");
      fclose(stream);
   }
   exit(0);
}

Additional reference words: 1.00 1.50 7.00 KBCategory: kbprg kbprb KBSubcategory: CRTIss Keywords : kb16bitonly

Last Reviewed: July 18, 1997