2018-12-30 00:27:58 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
#define HAVE_IRCD_FS_PATH_H
|
|
|
|
|
2019-01-25 19:35:39 +01:00
|
|
|
// Forward declarations for boost because it is not included here.
|
|
|
|
namespace boost::filesystem
|
|
|
|
{
|
|
|
|
struct path;
|
|
|
|
}
|
|
|
|
|
2018-12-30 00:27:58 +01:00
|
|
|
namespace ircd::fs
|
|
|
|
{
|
2020-04-19 00:29:04 +02:00
|
|
|
using path_views = vector_view<const string_view>;
|
2019-06-07 02:03:02 +02:00
|
|
|
using path_strings = vector_view<const std::string>;
|
2018-12-30 00:27:58 +01:00
|
|
|
|
2019-01-02 03:35:09 +01:00
|
|
|
extern const size_t NAME_MAX_LEN;
|
|
|
|
extern const size_t PATH_MAX_LEN;
|
2018-12-30 00:27:58 +01:00
|
|
|
|
2019-02-08 03:46:41 +01:00
|
|
|
// convenience tls buffers of appropriate size.
|
|
|
|
extern const mutable_buffer path_scratch;
|
|
|
|
extern const mutable_buffer name_scratch;
|
|
|
|
|
2019-01-25 19:35:39 +01:00
|
|
|
filesystem::path _path(std::string);
|
|
|
|
filesystem::path _path(const string_view &);
|
2020-04-19 00:29:04 +02:00
|
|
|
filesystem::path _path(const path_views &);
|
2019-06-07 02:03:02 +02:00
|
|
|
filesystem::path _path(const path_strings &);
|
2019-01-25 19:35:39 +01:00
|
|
|
|
2020-04-19 00:29:04 +02:00
|
|
|
string_view path(const mutable_buffer &, const path_views &);
|
2019-06-07 02:03:02 +02:00
|
|
|
string_view path(const mutable_buffer &, const path_strings &);
|
2019-01-25 20:26:35 +01:00
|
|
|
string_view path(const mutable_buffer &, const filesystem::path &);
|
2020-04-19 00:48:21 +02:00
|
|
|
|
2019-02-08 03:03:40 +01:00
|
|
|
template<class... A> std::string path_string(A&&...);
|
2020-04-19 00:48:21 +02:00
|
|
|
const char *path_cstr(const string_view &path); // rotating internal TLS buffer
|
2018-12-30 00:27:58 +01:00
|
|
|
|
2019-01-25 20:26:35 +01:00
|
|
|
bool is_relative(const string_view &path);
|
|
|
|
bool is_absolute(const string_view &path);
|
|
|
|
|
|
|
|
string_view extension(const mutable_buffer &, const string_view &path, const string_view &replace);
|
|
|
|
string_view extension(const mutable_buffer &, const string_view &path);
|
2019-02-08 05:22:55 +01:00
|
|
|
string_view relative(const mutable_buffer &, const string_view &root, const string_view &path);
|
2019-01-25 20:26:35 +01:00
|
|
|
string_view filename(const mutable_buffer &, const string_view &path);
|
|
|
|
string_view parent(const mutable_buffer &, const string_view &path);
|
2019-01-02 03:35:09 +01:00
|
|
|
|
2019-01-25 19:35:39 +01:00
|
|
|
long pathconf(const string_view &path, const int &arg);
|
2019-01-25 20:26:35 +01:00
|
|
|
size_t name_max_len(const string_view &path);
|
|
|
|
size_t path_max_len(const string_view &path);
|
2019-01-25 19:35:39 +01:00
|
|
|
|
2018-12-30 00:27:58 +01:00
|
|
|
string_view cwd(const mutable_buffer &buf);
|
|
|
|
std::string cwd();
|
|
|
|
}
|
|
|
|
|
2020-04-19 06:13:13 +02:00
|
|
|
/// Configuration items storing the base paths used at runtime for program
|
|
|
|
/// operation. The defaults are generated at ./configure time and obtained
|
|
|
|
/// from macros in config.h. As conf items, these values may be overriden by
|
|
|
|
/// environment variables and may be updated by conf loads from the database.
|
|
|
|
///
|
|
|
|
namespace ircd::fs::base
|
2018-12-30 00:27:58 +01:00
|
|
|
{
|
2020-04-19 06:13:13 +02:00
|
|
|
extern conf::item<std::string> prefix; // e.g. /usr
|
|
|
|
extern conf::item<std::string> bin; // e.g. /usr/bin
|
|
|
|
extern conf::item<std::string> etc; // e.g. /etc
|
|
|
|
extern conf::item<std::string> include; // e.g. /usr/include/ircd
|
|
|
|
extern conf::item<std::string> lib; // e.g. /usr/lib
|
|
|
|
extern conf::item<std::string> modules; // e.g. /usr/lib/modules/ircd
|
|
|
|
extern conf::item<std::string> share; // e.g. /usr/share/ircd
|
|
|
|
extern conf::item<std::string> run; // e.g. /var/run/ircd
|
|
|
|
extern conf::item<std::string> log; // e.g. /var/log/ircd
|
|
|
|
extern conf::item<std::string> db; // e.g. /var/db/ircd
|
|
|
|
}
|
2019-02-08 03:03:40 +01:00
|
|
|
|
|
|
|
template<class... A>
|
|
|
|
std::string
|
|
|
|
ircd::fs::path_string(A&&... a)
|
|
|
|
{
|
2019-05-17 07:54:29 +02:00
|
|
|
const size_t &size
|
2019-02-08 03:03:40 +01:00
|
|
|
{
|
|
|
|
PATH_MAX_LEN | SHRINK_TO_FIT
|
|
|
|
};
|
|
|
|
|
|
|
|
return util::string(size, [&a...]
|
|
|
|
(const mutable_buffer &buf)
|
|
|
|
{
|
|
|
|
return path(buf, std::forward<A>(a)...);
|
|
|
|
});
|
|
|
|
}
|