diff --git a/src/client.cc b/src/client.cc index 2ad7022a..ea6af7b9 100644 --- a/src/client.cc +++ b/src/client.cc @@ -121,7 +121,7 @@ void Client::redraw_ifn() context().ui().refresh(); } -static void reload_buffer(Context& context, const String& filename) +static void reload_buffer(Context& context, StringView filename) { CharCoord view_pos = context.window().position(); ByteCoord cursor_pos = context.selections().main().cursor(); diff --git a/src/file.cc b/src/file.cc index 472d3fb9..ae298ad2 100644 --- a/src/file.cc +++ b/src/file.cc @@ -132,29 +132,30 @@ String read_file(StringView filename) return read_fd(fd); } -Buffer* create_buffer_from_file(String filename) +Buffer* create_buffer_from_file(StringView filename) { - filename = real_path(parse_filename(filename)); + String real_filename = real_path(parse_filename(filename)); - int fd = open(filename.c_str(), O_RDONLY); + int fd = open(real_filename.c_str(), O_RDONLY); if (fd == -1) { if (errno == ENOENT) return nullptr; - throw file_access_error(filename, strerror(errno)); + throw file_access_error(real_filename, strerror(errno)); } auto close_fd = on_scope_end([&]{ close(fd); }); struct stat st; fstat(fd, &st); if (S_ISDIR(st.st_mode)) - throw file_access_error(filename, "is a directory"); + throw file_access_error(real_filename, "is a directory"); const char* data = (const char*)mmap(nullptr, st.st_size, PROT_READ, MAP_PRIVATE, fd, 0); auto unmap = on_scope_end([&]{ munmap((void*)data, st.st_size); }); - return create_buffer_from_data({data, data + st.st_size}, filename, Buffer::Flags::File, st.st_mtime); + return create_buffer_from_data({data, data + st.st_size}, real_filename, + Buffer::Flags::File, st.st_mtime); } static void write(int fd, StringView data) diff --git a/src/file.hh b/src/file.hh index 8cef4473..c8caaf75 100644 --- a/src/file.hh +++ b/src/file.hh @@ -36,7 +36,7 @@ String get_kak_binary_path(); String read_fd(int fd); String read_file(StringView filename); -Buffer* create_buffer_from_file(String filename); +Buffer* create_buffer_from_file(StringView filename); void write_buffer_to_file(Buffer& buffer, StringView filename); void write_buffer_to_fd(Buffer& buffer, int fd);