Exemplo n.º 1
0
int __cdecl _cputs (
        const char *string
        )
{
        ULONG num_written;
        int error = 0;                   /* error occurred? */

        _mlock(_CONIO_LOCK);             /* acquire console lock */

        /*
         * _confh, the handle to the console output, is created the
         * first time that either _putch() or _cputs() is called.
         */

        if (_confh == -2)
            __initconout();

        /* write string to console file handle */

        if ( (_confh == -1) || !WriteConsole( (HANDLE)_confh,
                                              (LPVOID)string,
                                              strlen(string),
                                              &num_written,
                                              NULL )
           )
                /* return error indicator */
                error = -1;

        _munlock(_CONIO_LOCK);          /* release console lock */

        return error;
}
Exemplo n.º 2
0
wint_t __cdecl _putwch_nolock (
        wchar_t ch
        )
{

    int size, num_written;
    static int use_w = 2;
    char mbc[MB_LEN_MAX +1];
    if ( use_w)
    {
        if (_confh == -2)
            __initconout();

        /* write character to console file handle */

        if (_confh == -1)
            return WEOF;
        else if ( !WriteConsoleW( (HANDLE)_confh,
                                  (LPVOID)&ch,
                                  1,
                                  &num_written,
                                  NULL )
                  )
        {
            if ( use_w == 2 && GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
                use_w = 0;
            else
                return WEOF;
        } else
                use_w = 1;
    }

    if ( use_w == 0)
    {
        size = WideCharToMultiByte(
                                   GetConsoleOutputCP(),
                                   0,
                                   (LPWSTR)&ch, 1,
                                   mbc,
                                   MB_LEN_MAX,
                                   NULL,
                                   NULL
                                   );
        if ( (_confh == -1) || !WriteConsole( (HANDLE)_confh,
                                              (LPVOID)mbc,
                                              size,
                                              &num_written,
                                              NULL )
           )
                /* return error indicator */
                return WEOF;
    }
    return ch;
}
Exemplo n.º 3
0
int __cdecl _cputs (
        const char *string
        )
{
        int error = 0;                   /* error occurred? */

        _VALIDATE_CLEAR_OSSERR_RETURN((string != NULL), EINVAL, -1);

        _mlock(_CONIO_LOCK);             /* acquire console lock */
        __try {

            /*
             * _confh, the handle to the console output, is created the
             * first time that either _putch() or _cputs() is called.
             */

            if (_confh == -2)
                __initconout();

            /* write string to console file handle */

            /*
             * What is more important when writing to console. I don't think if
             * speed should matter too much. This justification is used for writing
             * the string to Console. Here we are converting each and every
             * character to wide character and then writing it to console.
             */
            while(*string)
            {
                if (_putch_nolock(*string++) == EOF) {
                    error = -1;
                    break;
                }
            }

        }
        __finally {
            _munlock(_CONIO_LOCK);          /* release console lock */
        }

        return error;
}