Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fixup! src: use custom fprintf alike to write errors to stderr
  • Loading branch information
addaleax committed Jan 21, 2020
commit 3d905534f2af713725a39781efcc0cf4a6e6a140
15 changes: 11 additions & 4 deletions src/debug_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -442,15 +442,23 @@ std::vector<std::string> NativeSymbolDebuggingContext::GetLoadedLibraries() {
}

void FWrite(FILE* file, const std::string& str) {
if (file != stderr && file != stdout) goto simple_fwrite;
auto simple_fwrite = [&]() {
fwrite(str.data(), str.size(), 1, file);
Comment thread
addaleax marked this conversation as resolved.
Resolved
};

if (file != stderr && file != stdout) {
simple_fwrite();
return;
}
#ifdef _WIN32
HANDLE handle =
GetStdHandle(file == stdout ? STD_OUTPUT_HANDLE : STD_ERROR_HANDLE);

// Check if stderr is something other than a tty/console
if (handle == INVALID_HANDLE_VALUE || handle == nullptr ||
uv_guess_handle(_fileno(file)) != UV_TTY) {
goto simple_fwrite;
simple_fwrite();
return;
}

// Get required wide buffer size
Expand All @@ -469,8 +477,7 @@ void FWrite(FILE* file, const std::string& str) {
return;
}
#endif
simple_fwrite:
fwrite(str.data(), str.size(), 1, file);
simple_fwrite();
}

} // namespace node
Expand Down
2 changes: 1 addition & 1 deletion src/node_errors.cc
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ static std::string GetErrorSource(Isolate* isolate,
filename_string,
linenum,
sourceline.c_str());
CHECK_GE(buf.size(), 0);
CHECK_GT(buf.size(), 0);

constexpr int kUnderlineBufsize = 1020;
char underline_buf[kUnderlineBufsize + 4];
Expand Down