File: extract read_file function which returns file content in a string
This commit is contained in:
parent
a2dfcc232c
commit
de19aeb035
|
@ -13,7 +13,7 @@
|
||||||
namespace Kakoune
|
namespace Kakoune
|
||||||
{
|
{
|
||||||
|
|
||||||
Buffer* create_buffer_from_file(const std::string& filename)
|
std::string read_file(const std::string& filename)
|
||||||
{
|
{
|
||||||
int fd = open(filename.c_str(), O_RDONLY);
|
int fd = open(filename.c_str(), O_RDONLY);
|
||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
|
@ -35,6 +35,12 @@ Buffer* create_buffer_from_file(const std::string& filename)
|
||||||
content += std::string(buf, size);
|
content += std::string(buf, size);
|
||||||
}
|
}
|
||||||
close(fd);
|
close(fd);
|
||||||
|
return content;
|
||||||
|
}
|
||||||
|
|
||||||
|
Buffer* create_buffer_from_file(const std::string& filename)
|
||||||
|
{
|
||||||
|
std::string content = read_file(filename);
|
||||||
|
|
||||||
if (Buffer* buffer = BufferManager::instance().get_buffer(filename))
|
if (Buffer* buffer = BufferManager::instance().get_buffer(filename))
|
||||||
BufferManager::instance().delete_buffer(buffer);
|
BufferManager::instance().delete_buffer(buffer);
|
||||||
|
|
|
@ -23,6 +23,7 @@ struct file_not_found : file_access_error
|
||||||
};
|
};
|
||||||
|
|
||||||
class Buffer;
|
class Buffer;
|
||||||
|
std::string read_file(const std::string& filename);
|
||||||
Buffer* create_buffer_from_file(const std::string& filename);
|
Buffer* create_buffer_from_file(const std::string& filename);
|
||||||
void write_buffer_to_file(const Buffer& buffer, const std::string& filename);
|
void write_buffer_to_file(const Buffer& buffer, const std::string& filename);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user