mirror of
https://github.com/matrix-construct/construct
synced 2024-11-15 22:41:12 +01:00
ircd::fs: Add truncate() suite.
This commit is contained in:
parent
888862ec56
commit
0ce45b50d6
2 changed files with 25 additions and 0 deletions
|
@ -26,6 +26,10 @@ namespace ircd::fs
|
|||
// Yields ircd::ctx to overwrite (trunc) file from buffer; returns view of written portion
|
||||
const_buffer overwrite(const fd &, const const_buffer & = {}, const write_opts & = write_opts_default);
|
||||
const_buffer overwrite(const string_view &path, const const_buffer & = {}, const write_opts & = write_opts_default);
|
||||
|
||||
// Truncate file to explicit size
|
||||
void truncate(const fd &, const size_t &, const write_opts & = write_opts_default);
|
||||
void truncate(const string_view &path, const size_t &, const write_opts & = write_opts_default);
|
||||
}
|
||||
|
||||
/// Options for a write operation
|
||||
|
|
21
ircd/fs.cc
21
ircd/fs.cc
|
@ -383,6 +383,27 @@ ircd::fs::write_opts
|
|||
const ircd::fs::write_opts_default
|
||||
{};
|
||||
|
||||
void
|
||||
ircd::fs::truncate(const string_view &path,
|
||||
const size_t &size,
|
||||
const write_opts &opts)
|
||||
{
|
||||
const fd fd
|
||||
{
|
||||
path, std::ios::out | std::ios::trunc
|
||||
};
|
||||
|
||||
return truncate(fd, size, opts);
|
||||
}
|
||||
|
||||
void
|
||||
ircd::fs::truncate(const fd &fd,
|
||||
const size_t &size,
|
||||
const write_opts &opts)
|
||||
{
|
||||
syscall(::ftruncate, fd, size);
|
||||
}
|
||||
|
||||
ircd::const_buffer
|
||||
ircd::fs::overwrite(const string_view &path,
|
||||
const const_buffer &buf,
|
||||
|
|
Loading…
Reference in a new issue