Consolidate writing to fd

This commit is contained in:
Maxime Coste 2015-11-26 23:40:17 +00:00
parent 0b57103c72
commit a81dbd90a1
6 changed files with 10 additions and 13 deletions

View File

@ -162,8 +162,8 @@ void write_to_debug_buffer(StringView str)
{
if (not BufferManager::has_instance())
{
write(2, str.data(), (int)str.length());
write(2, "\n", 1);
write_stderr(str);
write_stderr("\n");
return;
}

View File

@ -197,7 +197,7 @@ bool file_exists(StringView filename)
return stat(real_filename.c_str(), &st) == 0;
}
static void write(int fd, StringView data)
void write(int fd, StringView data)
{
const char* ptr = data.data();
ssize_t count = (int)data.length();

View File

@ -42,6 +42,10 @@ String get_kak_binary_path();
String read_fd(int fd, bool text = false);
String read_file(StringView filename, bool text = false);
void write(int fd, StringView data);
inline void write_stdout(StringView str) { write(1, str); }
inline void write_stderr(StringView str) { write(2, str); }
struct MappedFile
{

View File

@ -44,14 +44,6 @@ String runtime_directory()
return "/usr/share/kak";
}
static void write(int fd, StringView str)
{
write(fd, str.data(), (size_t)(int)str.length());
}
static void write_stdout(StringView str) { write(1, str); }
static void write_stderr(StringView str) { write(2, str); }
void register_env_vars()
{
static const struct {

View File

@ -3,6 +3,7 @@
#include "containers.hh"
#include "display_buffer.hh"
#include "event_manager.hh"
#include "file.hh"
#include "keys.hh"
#include "register_manager.hh"
#include "utf8_iterator.hh"
@ -405,7 +406,7 @@ void NCursesUI::draw_status(const DisplayLine& status_line,
for (auto& atom : mode_line)
title += atom.content();
title += " - Kakoune\007";
write(1, title.data(), (int)title.length());
write_stdout(title);
}
m_dirty = true;

View File

@ -132,7 +132,7 @@ std::pair<String, int> ShellManager::eval(
child_stdout.close_write_fd();
child_stderr.close_write_fd();
write(child_stdin.write_fd(), input.data(), (int)input.length());
write(child_stdin.write_fd(), input);
child_stdin.close_write_fd();
auto wait_time = profile ? Clock::now() : TimePoint{};