0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-17 07:20:55 +01:00

ircd::fs: Add convenience tls scratch buffers for name and path manip.

This commit is contained in:
Jason Volk 2019-02-07 18:46:41 -08:00
parent 9f7db84dd3
commit 7b67b106b6
2 changed files with 50 additions and 30 deletions

View file

@ -25,6 +25,10 @@ namespace ircd::fs
extern const size_t NAME_MAX_LEN;
extern const size_t PATH_MAX_LEN;
// convenience tls buffers of appropriate size.
extern const mutable_buffer path_scratch;
extern const mutable_buffer name_scratch;
filesystem::path _path(std::string);
filesystem::path _path(const string_view &);
filesystem::path _path(const vector_view<const string_view> &);

View file

@ -25,32 +25,6 @@ namespace ircd::fs
static void debug_paths();
}
/// Default maximum path string length (for all filesystems & platforms).
decltype(ircd::fs::NAME_MAX_LEN)
ircd::fs::NAME_MAX_LEN
{
#ifdef NAME_MAX
NAME_MAX
#elif defined(_POSIX_NAME_MAX)
_POSIX_NAME_MAX
#else
255
#endif
};
/// Default maximum path string length (for all filesystems & platforms).
decltype(ircd::fs::PATH_MAX_LEN)
ircd::fs::PATH_MAX_LEN
{
#ifdef PATH_MAX
PATH_MAX
#elif defined(_POSIX_PATH_MAX)
_POSIX_PATH_MAX
#else
4096
#endif
};
//
// init
//
@ -1169,12 +1143,10 @@ ircd::fs::dev::sysfs(const mutable_buffer &out,
const ulong &id,
const string_view &relpath)
{
thread_local char pathbuf[PATH_MAX_LEN];
thread_local char idbuf[NAME_MAX_LEN];
const string_view path{fmt::sprintf
{
pathbuf, "/sys/dev/block/%s/%s",
sysfs_id(idbuf, id),
path_scratch, "/sys/dev/block/%s/%s",
sysfs_id(name_scratch, id),
relpath
}};
@ -1332,6 +1304,50 @@ ircd::fs::bytes(const const_iovec_view &iov)
// fs/path.h
//
/// Default maximum path string length (for all filesystems & platforms).
decltype(ircd::fs::NAME_MAX_LEN)
ircd::fs::NAME_MAX_LEN
{
#ifdef NAME_MAX
NAME_MAX
#elif defined(_POSIX_NAME_MAX)
_POSIX_NAME_MAX
#else
255
#endif
};
/// Default maximum path string length (for all filesystems & platforms).
decltype(ircd::fs::PATH_MAX_LEN)
ircd::fs::PATH_MAX_LEN
{
#ifdef PATH_MAX
PATH_MAX
#elif defined(_POSIX_PATH_MAX)
_POSIX_PATH_MAX
#else
4096
#endif
};
namespace ircd::fs
{
thread_local char _path_scratch[PATH_MAX_LEN];
thread_local char _name_scratch[NAME_MAX_LEN];
}
decltype(ircd::fs::path_scratch)
ircd::fs::path_scratch
{
_path_scratch
};
decltype(ircd::fs::name_scratch)
ircd::fs::name_scratch
{
_name_scratch
};
std::string
ircd::fs::cwd()
try