Changeset 2907


Ignore:
Timestamp:
Sep 10, 2016, 12:33:26 AM (9 years ago)
Author:
bird
Message:

do fprintf too.

Location:
trunk/src
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/kmk/Makefile.kmk

    r2899 r2907  
    5858 TEMPLATE_BIN-KMK_INCS += glob
    5959endif
    60 TEMPLATE_BIN-KMK_LIBS = $(TEMPLATE_BIN-THREADED_LIBS) $(kmkmissing_1_TARGET) $(LIB_KUTIL)
     60TEMPLATE_BIN-KMK_LIBS = $(LIB_KUTIL) $(TEMPLATE_BIN-THREADED_LIBS) $(kmkmissing_1_TARGET) $(LIB_KUTIL)
    6161ifdef ELECTRIC_HEAP # for electric heap (see electric.c) - windows only.
    6262ifeq ($(KBUILD_TARGET),win)
  • trunk/src/lib/msc_buffered_printf.c

    r2906 r2907  
    11/* $Id$ */
    22/** @file
    3  * printf and vprintf console optimizations for Windows/MSC.
     3 * printf, vprintf, fprintf, puts, fputs console optimizations for Windows/MSC.
    44 */
    55
     
    4242#undef printf
    4343#undef vprintf
     44#undef fprintf
    4445#undef puts
    4546#undef fputs
     
    101102     * Fallback.
    102103     */
    103     return fprintf(stdout, pszFormat, va);
     104    return vfprintf(stdout, pszFormat, va);
     105}
     106
     107
     108/**
     109 * Replaces fprintf for MSC to speed up console output.
     110 *
     111 * @returns chars written on success, -1 and errno on failure.
     112 * @param   pFile               The output file/stream.
     113 * @param   pszFormat           The format string.
     114 * @param   va                  Format arguments.
     115 */
     116__declspec(dllexport)
     117int __cdecl fprintf(FILE *pFile, const char *pszFormat, ...)
     118{
     119    va_list va;
     120    int cchRet;
     121
     122    /*
     123     * If it's a TTY, try format into a stack buffer and output using our
     124     * console optimized fwrite wrapper.
     125     */
     126    if (*pszFormat != '\0')
     127    {
     128        int fd = fileno(pFile);
     129        if (fd >= 0)
     130        {
     131            if (isatty(fd))
     132            {
     133                char szTmp[8192];
     134                va_start(va, pszFormat);
     135                cchRet = vsnprintf(szTmp, sizeof(szTmp), pszFormat, va);
     136                va_end(va);
     137                if (cchRet >= sizeof(szTmp) - 1)
     138                    return (int)maybe_con_fwrite(szTmp, cchRet, 1, pFile);
     139            }
     140        }
     141    }
     142
     143    /*
     144     * Fallback.
     145     */
     146    va_start(va, pszFormat);
     147    cchRet = vfprintf(pFile, pszFormat, va);
     148    va_end(va);
     149    return cchRet;
    104150}
    105151
     
    200246void * const __imp_printf  = (void *)(uintptr_t)printf;
    201247void * const __imp_vprintf = (void *)(uintptr_t)vprintf;
     248void * const __imp_fprintf = (void *)(uintptr_t)fprintf;
    202249void * const __imp_puts    = (void *)(uintptr_t)puts;
    203250void * const __imp_fputs   = (void *)(uintptr_t)fputs;
Note: See TracChangeset for help on using the changeset viewer.