diff options
| author | Maxime Coste <mawww@kakoune.org> | 2025-02-19 20:58:49 +1100 |
|---|---|---|
| committer | Maxime Coste <mawww@kakoune.org> | 2025-02-19 21:25:39 +1100 |
| commit | eb7d34333b0698e8e1a8af4f2be908ab08cb2089 (patch) | |
| tree | 4b53ba24111ce88901669c3e7651b5ec4edb4f87 /src/file.hh | |
| parent | 9eda509282ebc881207c2d8278085cb53835641c (diff) | |
Cleanup file.cc/hh dependencies
file.cc/hh should not know about Context, Buffer, etc... It should
be a pretty low level set of helper functions. Move buffer related
functions to buffer_utils and extract busy indicators to callers.
Diffstat (limited to 'src/file.hh')
| -rw-r--r-- | src/file.hh | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/src/file.hh b/src/file.hh index a0b55e56..3d0d8603 100644 --- a/src/file.hh +++ b/src/file.hh @@ -1,12 +1,13 @@ #ifndef file_hh_INCLUDED #define file_hh_INCLUDED +#include "array.hh" #include "array_view.hh" #include "enum.hh" +#include "exception.hh" #include "meta.hh" #include "string.hh" #include "units.hh" -#include "array.hh" #include "vector.hh" #include <sys/types.h> @@ -16,10 +17,16 @@ namespace Kakoune { -class Buffer; class String; class Regex; +struct file_access_error : runtime_error +{ + file_access_error(StringView filename, StringView error_desc); + file_access_error(int fd, StringView error_desc); +}; + + using CandidateList = Vector<String, MemoryDomain::Completion>; // parse ~/ and %/ in filename and returns the translated filename @@ -42,8 +49,10 @@ String read_fd(int fd, bool text = false); String read_file(StringView filename, bool text = false); template<bool force_blocking = false> void write(int fd, StringView data); -class Context; -void write_to_file(const Context&, StringView filename, StringView data); +void write_to_file(StringView filename, StringView data); +int create_file(const char* filename); +int open_temp_file(StringView filename); +int open_temp_file(StringView filename, char (&buffer)[PATH_MAX]); struct MappedFile { @@ -69,19 +78,6 @@ constexpr auto enum_desc(Meta::Type<WriteMethod>) }); } -enum class WriteFlags -{ - None = 0, - Force = 0b01, - Sync = 0b10 -}; -constexpr bool with_bit_ops(Meta::Type<WriteFlags>) { return true; } - -void write_buffer_to_file(const Context& context, Buffer& buffer, StringView filename, - WriteMethod method, WriteFlags flags); -void write_buffer_to_fd(Buffer& buffer, int fd); -void write_buffer_to_backup_file(Buffer& buffer); - String find_file(StringView filename, StringView buf_dir, ConstArrayView<String> paths); bool file_exists(StringView filename); bool regular_file_exists(StringView filename); @@ -90,6 +86,8 @@ Vector<String> list_files(StringView directory); void make_directory(StringView dir, mode_t mode); +constexpr timespec InvalidTime = { -1, -1 }; + struct FsStatus { timespec timestamp; |
