VirtualBox

Changeset 2733 in kBuild


Ignore:
Timestamp:
Oct 16, 2014 6:29:41 PM (11 years ago)
Author:
bird
Message:

mscfakes.c: Make sure STDOUT and STDERR are blocking before we use them. Fixes #120.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/kmkbuiltin/mscfakes.c

    r2702 r2733  
    110110
    111111int
    112 birdSetErrno(DWORD dwErr)
     112birdSetErrno(unsigned dwErr)
    113113{
    114114    switch (dwErr)
     
    535535
    536536
     537/**
     538 * This is a kludge to make pipe handles blocking.
     539 *
     540 * @returns TRUE if it's now blocking, FALSE if not a pipe or we failed to fix
     541 *          the blocking mode.
     542 * @param   fd                  The libc file descriptor number.
     543 */
     544static BOOL makePipeBlocking(int fd)
     545{
     546    /* Is pipe? */
     547    HANDLE hFile = (HANDLE)_get_osfhandle(fd);
     548    if (hFile != INVALID_HANDLE_VALUE)
     549    {
     550        DWORD fType = GetFileType(hFile);
     551        fType &= ~FILE_TYPE_REMOTE;
     552        if (fType == FILE_TYPE_PIPE)
     553        {
     554            /* Try fix it. */
     555            DWORD fState = 0;
     556            if (GetNamedPipeHandleState(hFile, &fState, NULL, NULL, NULL, NULL,  0))
     557            {
     558                fState &= ~PIPE_NOWAIT;
     559                fState |= PIPE_WAIT;
     560                if (SetNamedPipeHandleState(hFile, &fState, NULL, NULL))
     561                    return TRUE;
     562            }
     563        }
     564    }
     565    return FALSE;
     566}
     567
     568
     569/**
     570 * Initializes the msc fake stuff.
     571 * @returns 0 on success (non-zero would indicate failure, see rterr.h).
     572 */
     573int mscfake_init(void)
     574{
     575    /*
     576     * Kludge against _write returning ENOSPC on non-blocking pipes.
     577     */
     578    makePipeBlocking(STDOUT_FILENO);
     579    makePipeBlocking(STDERR_FILENO);
     580
     581    return 0;
     582}
     583
     584/*
     585 * Do this before main is called.
     586 */
     587#pragma section(".CRT$XIA", read)
     588#pragma section(".CRT$XIU", read)
     589#pragma section(".CRT$XIZ", read)
     590typedef int (__cdecl *PFNCRTINIT)(void);
     591static __declspec(allocate(".CRT$XIU")) PFNCRTINIT g_MscFakeInitVectorEntry = mscfake_init;
     592
Note: See TracChangeset for help on using the changeset viewer.

© 2025 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette