Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
8a8072e5
Commit
8a8072e5
authored
Oct 21, 2014
by
Joshua Warner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use KJ_STACK_ARRAY for win32 text buffers in main.c++
parent
c0fbfd9c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
11 additions
and
11 deletions
+11
-11
main.c++
c++/src/kj/main.c++
+11
-11
No files found.
c++/src/kj/main.c++
View file @
8a8072e5
...
...
@@ -73,8 +73,8 @@ static void writeLineToFd(int fd, StringPtr message) {
}
#if _WIN32
char
*
newlineExpansionBuffer
=
(
char
*
)
_alloca
(
2
*
(
message
.
size
()
+
1
)
);
char
*
p
=
newlineExpansionBuffer
;
KJ_STACK_ARRAY
(
char
,
newlineExpansionBuffer
,
2
*
(
message
.
size
()
+
1
),
128
,
512
);
char
*
p
=
newlineExpansionBuffer
.
begin
()
;
for
(
char
ch
:
message
)
{
if
(
ch
==
'\n'
)
{
*
(
p
++
)
=
'\r'
;
...
...
@@ -86,9 +86,9 @@ static void writeLineToFd(int fd, StringPtr message) {
*
(
p
++
)
=
'\n'
;
}
size_t
newlineExpandedSize
=
p
-
newlineExpansionBuffer
;
size_t
newlineExpandedSize
=
p
-
newlineExpansionBuffer
.
begin
()
;
KJ_ASSERT
(
newlineExpandedSize
<=
2
*
(
message
.
size
()
+
1
));
KJ_ASSERT
(
newlineExpandedSize
<=
newlineExpansionBuffer
.
size
(
));
HANDLE
handle
=
reinterpret_cast
<
HANDLE
>
(
_get_osfhandle
(
fd
));
DWORD
consoleMode
;
...
...
@@ -96,21 +96,21 @@ static void writeLineToFd(int fd, StringPtr message) {
DWORD
writtenSize
;
if
(
redirectedToFile
)
{
WriteFile
(
handle
,
newlineExpansionBuffer
,
newlineExpandedSize
,
&
writtenSize
,
nullptr
);
WriteFile
(
handle
,
newlineExpansionBuffer
.
begin
()
,
newlineExpandedSize
,
&
writtenSize
,
nullptr
);
}
else
{
wchar_t
*
buffer
=
(
wchar_t
*
)
_alloca
(
sizeof
(
wchar_t
)
*
newlineExpandedSize
);
KJ_STACK_ARRAY
(
wchar_t
,
buffer
,
newlineExpandedSize
,
128
,
512
);
size_t
finalSize
=
MultiByteToWideChar
(
CP_UTF8
,
0
,
newlineExpansionBuffer
,
newlineExpansionBuffer
.
begin
()
,
newlineExpandedSize
,
buffer
,
newlineExpandedSize
);
buffer
.
begin
()
,
buffer
.
size
()
);
KJ_ASSERT
(
finalSize
<=
newlineExpandedSize
);
KJ_ASSERT
(
finalSize
<=
buffer
.
size
()
);
WriteConsoleW
(
handle
,
buffer
,
finalSize
,
&
writtenSize
,
nullptr
);
WriteConsoleW
(
handle
,
buffer
.
begin
()
,
finalSize
,
&
writtenSize
,
nullptr
);
}
#else
// Unfortunately the writev interface requires non-const pointers even though it won't modify
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment