Changeset 3188 in kBuild
- Timestamp:
- Mar 24, 2018 3:32:26 PM (7 years ago)
- Location:
- trunk/src
- Files:
-
- 2 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/kWorker/Makefile.kmk
r3042 r3188 78 78 nt/kFsCache.c \ 79 79 quote_argv.c \ 80 is_console.c \ 80 81 maybe_con_write.c \ 81 82 maybe_con_fwrite.c \ -
trunk/src/kWorker/kWorker.c
r3089 r3188 56 56 #include "quote_argv.h" 57 57 #include "md5.h" 58 #include "console.h" 58 59 59 60 #include "../kmk/kmkbuiltin.h" … … 10716 10717 char sz3[64]; 10717 10718 char sz4[64]; 10718 extern size_t maybe_con_fwrite(void const *pvBuf, size_t cbUnit, size_t cUnits, FILE *pFile);10719 10719 10720 10720 sprintf(szPrf, "%5d/%u:", getpid(), K_ARCH_BITS); -
trunk/src/kmk/kmkbuiltin/err.c
r3065 r3188 36 36 #ifdef KBUILD_OS_WINDOWS 37 37 /* This is a trick to speed up console output on windows. */ 38 # include "console.h" 38 39 # undef fwrite 39 40 # define fwrite maybe_con_fwrite 40 extern size_t maybe_con_fwrite(void const *, size_t, size_t, FILE *);41 41 #endif 42 42 -
trunk/src/kmk/kmkbuiltin/mscfakes.c
r3140 r3188 45 45 #undef lutimes 46 46 47 extern ssize_t maybe_con_write(int, void const *, size_t); 47 #include "console.h" 48 48 49 49 50 … … 477 478 { 478 479 /* Console output optimization: */ 479 if (cbSrc > 0 && is atty(fd))480 if (cbSrc > 0 && is_console(fd)) 480 481 return maybe_con_write(fd, pvSrc, cbSrc); 481 482 … … 586 587 ssize_t writev(int fd, const struct iovec *vector, int count) 587 588 { 588 int size = 0; 589 int i; 590 for (i = 0; i < count; i++) 591 { 592 int cb = msc_write(fd, vector[i].iov_base, (int)vector[i].iov_len); 593 if (cb < 0) 594 return cb; 595 size += cb; 589 ssize_t size = 0; 590 if (count > 0) 591 { 592 int i; 593 594 /* To get consistent console output, we must try combine the segments 595 when outputing to the console. */ 596 if (count > 1 && is_console(fd)) 597 { 598 char *pbTmp; 599 ssize_t cbTotal; 600 if (count == 1) 601 return maybe_con_write(fd, vector[0].iov_base, (int)vector[0].iov_len); 602 603 cbTotal = 0; 604 for (i = 0; i < count; i++) 605 cbTotal += vector[i].iov_len; 606 pbTmp = malloc(cbTotal); 607 if (pbTmp) 608 { 609 char *pbCur = pbTmp; 610 for (i = 0; i < count; i++) 611 { 612 memcpy(pbCur, vector[i].iov_base, vector[i].iov_len); 613 pbCur += vector[i].iov_len; 614 } 615 size = maybe_con_write(fd, pbTmp, cbTotal); 616 free(pbTmp); 617 return size; 618 } 619 620 /* fall back on segment by segment output. */ 621 } 622 623 for (i = 0; i < count; i++) 624 { 625 int cb = msc_write(fd, vector[i].iov_base, (int)vector[i].iov_len); 626 if (cb < 0) 627 return cb; 628 size += cb; 629 } 596 630 } 597 631 return size; -
trunk/src/kmk/kmkbuiltin/mscfakes.h
r3140 r3188 90 90 typedef unsigned short gid_t; 91 91 #endif 92 #if defined(_M_AMD64) || defined(_M_X64) || defined(_M_IA64) || defined(_WIN64) 93 typedef __int64 ssize_t; 94 #else 95 typedef long ssize_t; 96 #endif 92 typedef intptr_t ssize_t; 97 93 typedef unsigned long u_long; 98 94 typedef unsigned int u_int; -
trunk/src/kmk/kmkbuiltin/printf.c
r3145 r3188 78 78 #ifdef KBUILD_OS_WINDOWS 79 79 /* This is a trick to speed up console output on windows. */ 80 # include "console.h" 80 81 # undef fwrite 81 82 # define fwrite maybe_con_fwrite 82 extern size_t maybe_con_fwrite(void const *, size_t, size_t, FILE *);83 83 #endif 84 84 -
trunk/src/kmk/output.c
r3156 r3188 43 43 # endif 44 44 #endif /* WINDOWS32 */ 45 #ifdef KBUILD_OS_WINDOWS 46 # include "console.h" 47 #endif 45 48 46 49 struct output *output_context = NULL; … … 66 69 #ifdef KBUILD_OS_WINDOWS 67 70 /** @todo check if fputs is also subject to char-by-char stupidity */ 68 extern size_t maybe_con_fwrite(void const *, size_t, size_t, FILE *);69 71 maybe_con_fwrite(msg, strlen(msg), 1, f); 70 72 #else -
trunk/src/lib/Makefile.kmk
r3179 r3188 41 41 maybe_con_write.c \ 42 42 maybe_con_fwrite.c \ 43 is_console.c \ 43 44 dos2unix.c \ 44 45 kbuild_version.c -
trunk/src/lib/maybe_con_fwrite.c
r2906 r3188 5 5 6 6 /* 7 * Copyright (c) 2016 knut st. osmundsen <[email protected]>7 * Copyright (c) 2016-2018 knut st. osmundsen <[email protected]> 8 8 * 9 9 * Permission is hereby granted, free of charge, to any person obtaining a … … 33 33 * Header Files * 34 34 *********************************************************************************************************************************/ 35 #include "console.h" 35 36 #ifdef KBUILD_OS_WINDOWS 36 37 # include <windows.h> 37 38 #endif 38 39 #include <errno.h> 39 #include <stdio.h>40 40 #ifdef _MSC_VER 41 # include <io.h>42 41 # include <conio.h> 43 42 #endif 44 45 43 46 44 … … 69 67 if (fd >= 0) 70 68 { 71 if (isatty(fd)) 69 HANDLE hCon = (HANDLE)_get_osfhandle(fd); 70 if ( hCon != INVALID_HANDLE_VALUE 71 && hCon != NULL) 72 72 { 73 HANDLE hCon = (HANDLE)_get_osfhandle(fd); 74 if ( hCon != INVALID_HANDLE_VALUE 75 && hCon != NULL) 73 if (is_console_handle((intptr_t)hCon)) 76 74 { 77 75 size_t cbToWrite = cbUnit * cUnits; … … 85 83 s_uConsoleCp = GetConsoleCP(); 86 84 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)); 88 87 if (cwcToWrite > 0) 89 88 { … … 92 91 93 92 /* 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. */ 95 94 fflush(pFile); 96 95 rc = _cputws(pawcTmp); … … 113 112 return fwrite(pvBuf, cbUnit, cUnits, pFile); 114 113 } 114 -
trunk/src/lib/maybe_con_write.c
r3065 r3188 5 5 6 6 /* 7 * Copyright (c) 2016 knut st. osmundsen <[email protected]>7 * Copyright (c) 2016-2018 knut st. osmundsen <[email protected]> 8 8 * 9 9 * Permission is hereby granted, free of charge, to any person obtaining a … … 33 33 * Header Files * 34 34 *********************************************************************************************************************************/ 35 #include "console.h" 35 36 #ifdef KBUILD_OS_WINDOWS 36 37 # include <windows.h> … … 38 39 #include <errno.h> 39 40 #ifdef _MSC_VER 40 # include <io.h>41 41 # include <conio.h> 42 typedef intptr_t ssize_t;43 42 typedef unsigned int to_write_t; 44 43 #else 45 # include <unistd.h>46 44 typedef size_t to_write_t; 47 45 #endif … … 56 54 * @param cbToWrite How much to write. 57 55 */ 58 ssize_t maybe_con_write(int fd, void *pvBuf, size_t cbToWrite)56 ssize_t maybe_con_write(int fd, void const *pvBuf, size_t cbToWrite) 59 57 { 60 58 ssize_t cbWritten; 59 61 60 #ifdef KBUILD_OS_WINDOWS 62 61 /* … … 64 63 * call WriteConsoleW directly. 65 64 */ 66 if (cbToWrite > 0 && isatty(fd))65 if (cbToWrite > 0) 67 66 { 68 67 HANDLE hCon = (HANDLE)_get_osfhandle(fd); … … 70 69 && hCon != NULL) 71 70 { 72 size_t cwcTmp = cbToWrite * 2 + 16; 73 wchar_t *pawcTmp = (wchar_t *)malloc(cwcTmp * sizeof(wchar_t)); 74 if (pawcTmp) 71 if (is_console_handle((intptr_t)hCon)) 75 72 { 76 int cwcToWrite; 77 static UINT s_uConsoleCp = 0; 78 if (s_uConsoleCp == 0) 79 s_uConsoleCp = GetConsoleCP(); 73 size_t cwcTmp = cbToWrite * 2 + 16; 74 wchar_t *pawcTmp = (wchar_t *)malloc(cwcTmp * sizeof(wchar_t)); 75 if (pawcTmp) 76 { 77 int cwcToWrite; 78 static UINT s_uConsoleCp = 0; 79 if (s_uConsoleCp == 0) 80 s_uConsoleCp = GetConsoleCP(); 80 81 81 cwcToWrite = MultiByteToWideChar(s_uConsoleCp, 0 /*dwFlags*/, pvBuf, (int)cbToWrite, pawcTmp, (int)(cwcTmp - 1)); 82 if (cwcToWrite > 0) 83 { 84 /* Let the CRT do the rest. At least the Visual C++ 2010 CRT 85 sources indicates _cputws will do the right thing we want. */ 86 pawcTmp[cwcToWrite] = '\0'; 87 if (_cputws(pawcTmp) >= 0) 88 return cbToWrite; 89 return -1; 82 cwcToWrite = MultiByteToWideChar(s_uConsoleCp, 0 /*dwFlags*/, pvBuf, (int)cbToWrite, 83 pawcTmp, (int)(cwcTmp - 1)); 84 if (cwcToWrite > 0) 85 { 86 /* Let the CRT do the rest. At least the Visual C++ 2010 CRT 87 sources indicates _cputws will do the right thing. */ 88 pawcTmp[cwcToWrite] = '\0'; 89 if (_cputws(pawcTmp) >= 0) 90 return cbToWrite; 91 return -1; 92 } 90 93 } 91 94 } … … 115 118 return cbWritten; 116 119 } 120 -
trunk/src/lib/msc_buffered_printf.c
r2967 r3188 39 39 #include <conio.h> 40 40 #include <malloc.h> 41 #include "console.h" 41 42 42 43 #undef printf … … 53 54 #endif 54 55 55 extern size_t maybe_con_fwrite(void const *pvBuf, size_t cbUnit, size_t cUnits, FILE *pFile);56 56 57 57 … … 94 94 if (fd >= 0) 95 95 { 96 if (is atty(fd))96 if (is_console(fd)) 97 97 { 98 98 char *pszTmp = (char *)alloca(16384); … … 135 135 if (fd >= 0) 136 136 { 137 if (is atty(fd))137 if (is_console(fd)) 138 138 { 139 139 char *pszTmp = (char *)alloca(16384); … … 182 182 if (fd >= 0) 183 183 { 184 if (is atty(fd))184 if (is_console(fd)) 185 185 { 186 186 HANDLE hCon = (HANDLE)_get_osfhandle(fd); -
trunk/src/sed/config.h.win
r1105 r3188 373 373 374 374 /* Define to `int' if <sys/types.h> does not define. */ 375 #define ssize_t int /* does 14.0 have this? */375 #define ssize_t intptr_t /* does 14.0 have this? */ 376 376 377 377 /* Additional defines and includes to make it work with the microsoft compiler */ -
trunk/src/sed/lib/utils.c
r2909 r3188 39 39 40 40 #ifdef KBUILD_OS_WINDOWS /* bird: Way faster console output! */ 41 extern size_t maybe_con_fwrite(void const *, size_t, size_t, FILE *); 41 # include "console.h" 42 42 # define fwrite maybe_con_fwrite 43 43 #endif
Note:
See TracChangeset
for help on using the changeset viewer.