dlls/msvcrt/file.c
/* INTERNAL: Set up all file descriptors, 
 * as well as default streams (stdin, stderr and stdout) 
 */
Set up all file descriptors,
as well as default streams (stdin, stderr and stdout)
Set up all file descriptors as well as default streams ( stdin stderr and stdout )
void msvcrt_init_io(void)
{
  STARTUPINFOA  si;
  int           i;
  ioinfo        *fdinfo;
  GetStartupInfoA(&si);
  if (si.cbReserved2 >= sizeof(unsigned int) && si.lpReserved2 != NULL)
  {
    BYTE*       wxflag_ptr;
    HANDLE*     handle_ptr;
    unsigned int count;
    count = *(unsigned*)si.lpReserved2;
    wxflag_ptr = si.lpReserved2 + sizeof(unsigned);
    handle_ptr = (HANDLE*)(wxflag_ptr + count);
    count = min(count, (si.cbReserved2 - sizeof(unsigned)) / (sizeof(HANDLE) + 1));
    count = min(count, MSVCRT_MAX_FILES);
    for (i = 0; i < count; i++)
    {
      if ((*wxflag_ptr & WX_OPEN) && *handle_ptr != INVALID_HANDLE_VALUE)
        msvcrt_set_fd(*handle_ptr, *wxflag_ptr, i);
      wxflag_ptr++; handle_ptr++;
    }
    MSVCRT_fdend = max( 3, count );
    for (MSVCRT_fdstart = 3; MSVCRT_fdstart < MSVCRT_fdend; MSVCRT_fdstart++)
        if (msvcrt_get_ioinfo(MSVCRT_fdstart)->handle == INVALID_HANDLE_VALUE) break;
  }
  fdinfo = msvcrt_get_ioinfo(MSVCRT_STDIN_FILENO);
  if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE)
    msvcrt_set_fd(GetStdHandle(STD_INPUT_HANDLE), WX_OPEN|WX_TEXT, MSVCRT_STDIN_FILENO);
  fdinfo = msvcrt_get_ioinfo(MSVCRT_STDOUT_FILENO);
  if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE)
    msvcrt_set_fd(GetStdHandle(STD_OUTPUT_HANDLE), WX_OPEN|WX_TEXT, MSVCRT_STDOUT_FILENO);
  fdinfo = msvcrt_get_ioinfo(MSVCRT_STDERR_FILENO);
  if (!(fdinfo->wxflag & WX_OPEN) || fdinfo->handle == INVALID_HANDLE_VALUE)
    msvcrt_set_fd(GetStdHandle(STD_ERROR_HANDLE), WX_OPEN|WX_TEXT, MSVCRT_STDERR_FILENO);
  TRACE(":handles (%p)(%p)(%p)\n", msvcrt_get_ioinfo(MSVCRT_STDIN_FILENO)->handle,
        msvcrt_get_ioinfo(MSVCRT_STDOUT_FILENO)->handle,
        msvcrt_get_ioinfo(MSVCRT_STDERR_FILENO)->handle);
  memset(MSVCRT__iob,0,3*sizeof(MSVCRT_FILE));
  for (i = 0; i < 3; i++)
  {
    MSVCRT__iob[i]._file = i;
    MSVCRT__iob[i]._tmpfname = NULL;
    MSVCRT__iob[i]._flag = (i == 0) ? MSVCRT__IOREAD : MSVCRT__IOWRT;
  }
  MSVCRT_stream_idx = 3;
}
void msvcrt_init_io ( void ) { STARTUPINFOA si ; int i ; ioinfo * fdinfo ; GetStartupInfoA ( & si ) ; if ( si . cbReserved2 >= sizeof ( unsigned int ) && si . lpReserved2 != NULL ) { BYTE * wxflag_ptr ; HANDLE * handle_ptr ; unsigned int count ; count = * ( unsigned * ) si . lpReserved2 ; wxflag_ptr = si . lpReserved2 + sizeof ( unsigned ) ; handle_ptr = ( HANDLE * ) ( wxflag_ptr + count ) ; count = min ( count , ( si . cbReserved2 - sizeof ( unsigned ) ) / ( sizeof ( HANDLE ) + 1 ) ) ; count = min ( count , MSVCRT_MAX_FILES ) ; for ( i = 0 ; i < count ; i ++ ) { if ( ( * wxflag_ptr & WX_OPEN ) && * handle_ptr != INVALID_HANDLE_VALUE ) msvcrt_set_fd ( * handle_ptr , * wxflag_ptr , i ) ; wxflag_ptr ++ ; handle_ptr ++ ; } MSVCRT_fdend = max ( 3 , count ) ; for ( MSVCRT_fdstart = 3 ; MSVCRT_fdstart < MSVCRT_fdend ; MSVCRT_fdstart ++ ) if ( msvcrt_get_ioinfo ( MSVCRT_fdstart ) -> handle == INVALID_HANDLE_VALUE ) break ; } fdinfo = msvcrt_get_ioinfo ( MSVCRT_STDIN_FILENO ) ; if ( ! ( fdinfo -> wxflag & WX_OPEN ) || fdinfo -> handle == INVALID_HANDLE_VALUE ) msvcrt_set_fd ( GetStdHandle ( STD_INPUT_HANDLE ) , WX_OPEN | WX_TEXT , MSVCRT_STDIN_FILENO ) ; fdinfo = msvcrt_get_ioinfo ( MSVCRT_STDOUT_FILENO ) ; if ( ! ( fdinfo -> wxflag & WX_OPEN ) || fdinfo -> handle == INVALID_HANDLE_VALUE ) msvcrt_set_fd ( GetStdHandle ( STD_OUTPUT_HANDLE ) , WX_OPEN | WX_TEXT , MSVCRT_STDOUT_FILENO ) ; fdinfo = msvcrt_get_ioinfo ( MSVCRT_STDERR_FILENO ) ; if ( ! ( fdinfo -> wxflag & WX_OPEN ) || fdinfo -> handle == INVALID_HANDLE_VALUE ) msvcrt_set_fd ( GetStdHandle ( STD_ERROR_HANDLE ) , WX_OPEN | WX_TEXT , MSVCRT_STDERR_FILENO ) ; TRACE ( " \n " , msvcrt_get_ioinfo ( MSVCRT_STDIN_FILENO ) -> handle , msvcrt_get_ioinfo ( MSVCRT_STDOUT_FILENO ) -> handle , msvcrt_get_ioinfo ( MSVCRT_STDERR_FILENO ) -> handle ) ; memset ( MSVCRT__iob , 0 , 3 * sizeof ( MSVCRT_FILE ) ) ; for ( i = 0 ; i < 3 ; i ++ ) { MSVCRT__iob [ i ] . _file = i ; MSVCRT__iob [ i ] . _tmpfname = NULL ; MSVCRT__iob [ i ] . _flag = ( i == 0 ) ? MSVCRT__IOREAD : MSVCRT__IOWRT ; } MSVCRT_stream_idx = 3 ; }
INTERNAL: Set up all file descriptors,
 as well as default streams (stdin, stderr and stdout)
INTERNAL : Set up all file descriptors as well as default streams ( stdin stderr and stdout )
/* FILE structs for stdin/out/err are static and never deleted */