Ignore:
Timestamp:
Mar 24, 2018, 4:32:26 PM (7 years ago)
Author:
bird
Message:

kmk,lib,kWorker: Console output on windows cleanups.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/maybe_con_fwrite.c

    r2906 r3188  
    55
    66/*
    7  * Copyright (c) 2016 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
     7 * Copyright (c) 2016-2018 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
    88 *
    99 * Permission is hereby granted, free of charge, to any person obtaining a
     
    3333*   Header Files                                                                                                                 *
    3434*********************************************************************************************************************************/
     35#include "console.h"
    3536#ifdef KBUILD_OS_WINDOWS
    3637# include <windows.h>
    3738#endif
    3839#include <errno.h>
    39 #include <stdio.h>
    4040#ifdef _MSC_VER
    41 # include <io.h>
    4241# include <conio.h>
    4342#endif
    44 
    4543
    4644
     
    6967        if (fd >= 0)
    7068        {
    71             if (isatty(fd))
     69            HANDLE hCon = (HANDLE)_get_osfhandle(fd);
     70            if (   hCon != INVALID_HANDLE_VALUE
     71                && hCon != NULL)
    7272            {
    73                 HANDLE hCon = (HANDLE)_get_osfhandle(fd);
    74                 if (   hCon != INVALID_HANDLE_VALUE
    75                     && hCon != NULL)
     73                if (is_console_handle((intptr_t)hCon))
    7674                {
    7775                    size_t   cbToWrite = cbUnit * cUnits;
     
    8583                            s_uConsoleCp = GetConsoleCP();
    8684
    87                         cwcToWrite = MultiByteToWideChar(s_uConsoleCp, 0 /*dwFlags*/, pvBuf, (int)cbToWrite, pawcTmp, (int)(cwcTmp - 1));
     85                        cwcToWrite = MultiByteToWideChar(s_uConsoleCp, 0 /*dwFlags*/, pvBuf, (int)cbToWrite,
     86                                                         pawcTmp, (int)(cwcTmp - 1));
    8887                        if (cwcToWrite > 0)
    8988                        {
     
    9291
    9392                            /* Let the CRT do the rest.  At least the Visual C++ 2010 CRT
    94                                sources indicates _cputws will do the right thing we want.  */
     93                               sources indicates _cputws will do the right thing.  */
    9594                            fflush(pFile);
    9695                            rc = _cputws(pawcTmp);
     
    113112    return fwrite(pvBuf, cbUnit, cUnits, pFile);
    114113}
     114
Note: See TracChangeset for help on using the changeset viewer.