Changeset 3188 for trunk/src/lib
- Timestamp:
- Mar 24, 2018, 4:32:26 PM (7 years ago)
- Location:
- trunk/src/lib
- Files:
-
- 2 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
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 <bird-kBuild-spamx@anduin.net>7 * Copyright (c) 2016-2018 knut st. osmundsen <bird-kBuild-spamx@anduin.net> 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 <bird-kBuild-spamx@anduin.net>7 * Copyright (c) 2016-2018 knut st. osmundsen <bird-kBuild-spamx@anduin.net> 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);
Note:
See TracChangeset
for help on using the changeset viewer.