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
a959e8f9
Commit
a959e8f9
authored
Oct 09, 2014
by
Joshua Warner
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
initial fixes for building kj/main.c++ utilities on mingw
parent
7f64b969
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
1 deletion
+33
-1
debug.c++
c++/src/kj/debug.c++
+4
-0
main.c++
c++/src/kj/main.c++
+29
-1
No files found.
c++/src/kj/debug.c++
View file @
a959e8f9
...
...
@@ -25,6 +25,10 @@
#include <string.h>
#include <errno.h>
#if _WIN32
#define strerror_r(errno,buf,len) strerror_s(buf,len,errno)
#endif
namespace
kj
{
namespace
_
{
// private
...
...
c++/src/kj/main.c++
View file @
a959e8f9
...
...
@@ -28,7 +28,13 @@
#include <unistd.h>
#include <errno.h>
#include <limits.h>
#if _WIN32
#include <windows.h>
#include <io.h>
#else
#include <sys/uio.h>
#endif
namespace
kj
{
...
...
@@ -60,12 +66,33 @@ void TopLevelProcessContext::exit() {
static
void
writeLineToFd
(
int
fd
,
StringPtr
message
)
{
// Write the given message to the given file descriptor with a trailing newline iff the message
// is non-empty and doesn't already have a trailing newline. We use writev() to do this in a
// single system call without any copying.
// single system call without any copying
(OS permitting)
.
if
(
message
.
size
()
==
0
)
{
return
;
}
#if _WIN32
// Sadly, there doesn't seem to be an API on windows that atomically writes data from multiple buffers.
// Also, windows APIs always expect unicode, not utf8. Therefore, we must convert the data every time.
HANDLE
handle
=
reinterpret_cast
<
HANDLE
>
(
_get_osfhandle
(
fd
));
size_t
bufferCharCount
=
message
.
size
()
+
1
;
wchar_t
*
buffer
=
(
wchar_t
*
)
_alloca
(
sizeof
(
wchar_t
)
*
bufferCharCount
);
size_t
finalSize
=
MultiByteToWideChar
(
CP_UTF8
,
0
,
message
.
begin
(),
message
.
size
(),
buffer
,
bufferCharCount
);
// We should always have at least one character of extra space for the possible '\n'.
KJ_ASSERT
(
finalSize
<
bufferCharCount
);
if
(
buffer
[
finalSize
-
1
]
!=
'\n'
)
{
buffer
[
finalSize
++
]
=
'\n'
;
}
DWORD
writtenSize
;
WriteFile
(
handle
,
buffer
,
finalSize
*
sizeof
(
wchar_t
),
&
writtenSize
,
nullptr
);
#else
// Unfortunately the writev interface requires non-const pointers even though it won't modify
// the data.
struct
iovec
vec
[
2
];
...
...
@@ -109,6 +136,7 @@ static void writeLineToFd(int fd, StringPtr message) {
}
}
}
#endif
}
void
TopLevelProcessContext
::
warning
(
StringPtr
message
)
{
...
...
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