Commit bbc52124 authored by Max Kellermann's avatar Max Kellermann

fs/AllocatedPath: make the nullptr_t constructor public

parent c4f7740b
...@@ -67,7 +67,7 @@ struct LocatedUri { ...@@ -67,7 +67,7 @@ struct LocatedUri {
AllocatedPath path; AllocatedPath path;
LocatedUri(Type _type, const char *_uri, LocatedUri(Type _type, const char *_uri,
AllocatedPath &&_path=AllocatedPath::Null()) AllocatedPath &&_path=nullptr)
:type(_type), canonical_uri(_uri), path(std::move(_path)) {} :type(_type), canonical_uri(_uri), path(std::move(_path)) {}
}; };
......
...@@ -46,7 +46,7 @@ static constexpr Domain log_domain("log"); ...@@ -46,7 +46,7 @@ static constexpr Domain log_domain("log");
#ifndef ANDROID #ifndef ANDROID
static int out_fd = -1; static int out_fd = -1;
static AllocatedPath out_path = AllocatedPath::Null(); static AllocatedPath out_path = nullptr;
static void redirect_logs(int fd) static void redirect_logs(int fd)
{ {
...@@ -169,7 +169,7 @@ log_deinit(void) ...@@ -169,7 +169,7 @@ log_deinit(void)
{ {
#ifndef ANDROID #ifndef ANDROID
close_log_files(); close_log_files();
out_path = AllocatedPath::Null(); out_path = nullptr;
#endif #endif
} }
......
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
* The absolute path of the playlist directory encoded in the * The absolute path of the playlist directory encoded in the
* filesystem character set. * filesystem character set.
*/ */
static AllocatedPath playlist_dir_fs = AllocatedPath::Null(); static AllocatedPath playlist_dir_fs = nullptr;
static void static void
mapper_set_playlist_dir(AllocatedPath &&path) mapper_set_playlist_dir(AllocatedPath &&path)
...@@ -72,15 +72,15 @@ map_uri_fs(const char *uri) noexcept ...@@ -72,15 +72,15 @@ map_uri_fs(const char *uri) noexcept
assert(*uri != '/'); assert(*uri != '/');
if (instance->storage == nullptr) if (instance->storage == nullptr)
return AllocatedPath::Null(); return nullptr;
const auto music_dir_fs = instance->storage->MapFS(""); const auto music_dir_fs = instance->storage->MapFS("");
if (music_dir_fs.IsNull()) if (music_dir_fs.IsNull())
return AllocatedPath::Null(); return nullptr;
const auto uri_fs = AllocatedPath::FromUTF8(uri); const auto uri_fs = AllocatedPath::FromUTF8(uri);
if (uri_fs.IsNull()) if (uri_fs.IsNull())
return AllocatedPath::Null(); return nullptr;
return AllocatedPath::Build(music_dir_fs, uri_fs); return AllocatedPath::Build(music_dir_fs, uri_fs);
} }
...@@ -118,7 +118,7 @@ AllocatedPath ...@@ -118,7 +118,7 @@ AllocatedPath
map_spl_utf8_to_fs(const char *name) noexcept map_spl_utf8_to_fs(const char *name) noexcept
{ {
if (playlist_dir_fs.IsNull()) if (playlist_dir_fs.IsNull())
return AllocatedPath::Null(); return nullptr;
std::string filename_utf8 = name; std::string filename_utf8 = name;
filename_utf8.append(PLAYLIST_FILE_SUFFIX); filename_utf8.append(PLAYLIST_FILE_SUFFIX);
...@@ -126,7 +126,7 @@ map_spl_utf8_to_fs(const char *name) noexcept ...@@ -126,7 +126,7 @@ map_spl_utf8_to_fs(const char *name) noexcept
const auto filename_fs = const auto filename_fs =
AllocatedPath::FromUTF8(filename_utf8.c_str()); AllocatedPath::FromUTF8(filename_utf8.c_str());
if (filename_fs.IsNull()) if (filename_fs.IsNull())
return AllocatedPath::Null(); return nullptr;
return AllocatedPath::Build(playlist_dir_fs, filename_fs); return AllocatedPath::Build(playlist_dir_fs, filename_fs);
} }
...@@ -36,7 +36,7 @@ Context::GetCacheDir(JNIEnv *env) const ...@@ -36,7 +36,7 @@ Context::GetCacheDir(JNIEnv *env) const
jobject file = env->CallObjectMethod(Get(), method); jobject file = env->CallObjectMethod(Get(), method);
if (file == nullptr) { if (file == nullptr) {
env->ExceptionClear(); env->ExceptionClear();
return AllocatedPath::Null(); return nullptr;
} }
return Java::File::ToAbsolutePath(env, file); return Java::File::ToAbsolutePath(env, file);
......
...@@ -60,7 +60,7 @@ Environment::getExternalStorageDirectory() ...@@ -60,7 +60,7 @@ Environment::getExternalStorageDirectory()
env->CallStaticObjectMethod(cls, env->CallStaticObjectMethod(cls,
getExternalStorageDirectory_method); getExternalStorageDirectory_method);
if (file == nullptr) if (file == nullptr)
return AllocatedPath::Null(); return nullptr;
return Java::File::ToAbsolutePath(env, file); return Java::File::ToAbsolutePath(env, file);
} }
...@@ -70,7 +70,7 @@ Environment::getExternalStoragePublicDirectory(const char *type) ...@@ -70,7 +70,7 @@ Environment::getExternalStoragePublicDirectory(const char *type)
{ {
if (getExternalStoragePublicDirectory_method == nullptr) if (getExternalStoragePublicDirectory_method == nullptr)
/* needs API level 8 */ /* needs API level 8 */
return AllocatedPath::Null(); return nullptr;
JNIEnv *env = Java::GetEnv(); JNIEnv *env = Java::GetEnv();
...@@ -79,7 +79,7 @@ Environment::getExternalStoragePublicDirectory(const char *type) ...@@ -79,7 +79,7 @@ Environment::getExternalStoragePublicDirectory(const char *type)
Environment::getExternalStoragePublicDirectory_method, Environment::getExternalStoragePublicDirectory_method,
type2.Get()); type2.Get());
if (file == nullptr) if (file == nullptr)
return AllocatedPath::Null(); return nullptr;
return Java::File::ToAbsolutePath(env, file); return Java::File::ToAbsolutePath(env, file);
} }
...@@ -118,7 +118,7 @@ ConfigBlock::GetPath(const char *name, const char *default_value) const ...@@ -118,7 +118,7 @@ ConfigBlock::GetPath(const char *name, const char *default_value) const
s = bp->value.c_str(); s = bp->value.c_str();
} else { } else {
if (default_value == nullptr) if (default_value == nullptr)
return AllocatedPath::Null(); return nullptr;
s = default_value; s = default_value;
} }
......
...@@ -125,7 +125,7 @@ config_get_path(ConfigOption option) ...@@ -125,7 +125,7 @@ config_get_path(ConfigOption option)
{ {
const auto *param = config_get_param(option); const auto *param = config_get_param(option);
if (param == nullptr) if (param == nullptr)
return AllocatedPath::Null(); return nullptr;
return param->GetPath(); return param->GetPath();
} }
......
...@@ -71,7 +71,7 @@ config_get_string(enum ConfigOption option, ...@@ -71,7 +71,7 @@ config_get_string(enum ConfigOption option,
/** /**
* Returns an optional configuration variable which contains an * Returns an optional configuration variable which contains an
* absolute path. If there is a tilde prefix, it is expanded. * absolute path. If there is a tilde prefix, it is expanded.
* Returns AllocatedPath::Null() if the value is not present. * Returns nullptr if the value is not present.
* *
* Throws #std::runtime_error on error. * Throws #std::runtime_error on error.
*/ */
......
...@@ -86,7 +86,7 @@ ParsePath(const char *path) ...@@ -86,7 +86,7 @@ ParsePath(const char *path)
if (*path == '\0') if (*path == '\0')
return GetConfiguredHome(); return GetConfiguredHome();
AllocatedPath home = AllocatedPath::Null(); AllocatedPath home = nullptr;
if (*path == '/') { if (*path == '/') {
home = GetConfiguredHome(); home = GetConfiguredHome();
...@@ -107,11 +107,11 @@ ParsePath(const char *path) ...@@ -107,11 +107,11 @@ ParsePath(const char *path)
} }
if (home.IsNull()) if (home.IsNull())
return AllocatedPath::Null(); return nullptr;
AllocatedPath path2 = AllocatedPath::FromUTF8Throw(path); AllocatedPath path2 = AllocatedPath::FromUTF8Throw(path);
if (path2.IsNull()) if (path2.IsNull())
return AllocatedPath::Null(); return nullptr;
return AllocatedPath::Build(home, path2); return AllocatedPath::Build(home, path2);
} else if (!PathTraitsUTF8::IsAbsolute(path)) { } else if (!PathTraitsUTF8::IsAbsolute(path)) {
......
...@@ -79,7 +79,7 @@ inline SimpleDatabase::SimpleDatabase(AllocatedPath &&_path, ...@@ -79,7 +79,7 @@ inline SimpleDatabase::SimpleDatabase(AllocatedPath &&_path,
#ifdef ENABLE_ZLIB #ifdef ENABLE_ZLIB
compress(_compress), compress(_compress),
#endif #endif
cache_path(AllocatedPath::Null()), cache_path(nullptr),
prefixed_light_song(nullptr) { prefixed_light_song(nullptr) {
} }
......
...@@ -135,7 +135,7 @@ AllocatedPath ...@@ -135,7 +135,7 @@ AllocatedPath
WatchDirectory::GetUriFS() const noexcept WatchDirectory::GetUriFS() const noexcept
{ {
if (parent == nullptr) if (parent == nullptr)
return AllocatedPath::Null(); return nullptr;
const auto uri = parent->GetUriFS(); const auto uri = parent->GetUriFS();
if (uri.IsNull()) if (uri.IsNull())
......
...@@ -499,7 +499,7 @@ try { ...@@ -499,7 +499,7 @@ try {
const char *const uri_utf8 = song.GetRealURI(); const char *const uri_utf8 = song.GetRealURI();
Path path_fs = nullptr; Path path_fs = nullptr;
AllocatedPath path_buffer = AllocatedPath::Null(); AllocatedPath path_buffer = nullptr;
if (PathTraitsUTF8::IsAbsolute(uri_utf8)) { if (PathTraitsUTF8::IsAbsolute(uri_utf8)) {
path_buffer = AllocatedPath::FromUTF8Throw(uri_utf8); path_buffer = AllocatedPath::FromUTF8Throw(uri_utf8);
path_fs = path_buffer; path_fs = path_buffer;
......
...@@ -71,7 +71,7 @@ public: ...@@ -71,7 +71,7 @@ public:
:SocketMonitor(_loop), :SocketMonitor(_loop),
parent(_parent), serial(_serial), parent(_parent), serial(_serial),
#ifdef HAVE_UN #ifdef HAVE_UN
path(AllocatedPath::Null()), path(nullptr),
#endif #endif
address(std::forward<A>(_address)) address(std::forward<A>(_address))
{ {
......
...@@ -43,7 +43,6 @@ class AllocatedPath { ...@@ -43,7 +43,6 @@ class AllocatedPath {
string value; string value;
AllocatedPath(std::nullptr_t):value() {}
explicit AllocatedPath(const_pointer_type _value):value(_value) {} explicit AllocatedPath(const_pointer_type _value):value(_value) {}
AllocatedPath(const_pointer_type _begin, const_pointer_type _end) AllocatedPath(const_pointer_type _begin, const_pointer_type _end)
...@@ -57,6 +56,14 @@ class AllocatedPath { ...@@ -57,6 +56,14 @@ class AllocatedPath {
} }
public: public:
/** /**
* Construct a "nulled" instance. Its IsNull() method will
* return true. Such an object must not be used.
*
* @see IsNull()
*/
AllocatedPath(std::nullptr_t):value() {}
/**
* Copy an #AllocatedPath object. * Copy an #AllocatedPath object.
*/ */
AllocatedPath(const AllocatedPath &) = default; AllocatedPath(const AllocatedPath &) = default;
...@@ -70,17 +77,6 @@ public: ...@@ -70,17 +77,6 @@ public:
~AllocatedPath(); ~AllocatedPath();
/**
* Return a "nulled" instance. Its IsNull() method will
* return true. Such an object must not be used.
*
* @see IsNull()
*/
gcc_const
static AllocatedPath Null() noexcept {
return AllocatedPath(nullptr);
}
gcc_pure gcc_pure
operator Path() const noexcept { operator Path() const noexcept {
return Path::FromFS(c_str()); return Path::FromFS(c_str());
......
...@@ -45,15 +45,15 @@ ReadLink(Path path) ...@@ -45,15 +45,15 @@ ReadLink(Path path)
#ifdef _WIN32 #ifdef _WIN32
(void)path; (void)path;
errno = EINVAL; errno = EINVAL;
return AllocatedPath::Null(); return nullptr;
#else #else
char buffer[MPD_PATH_MAX]; char buffer[MPD_PATH_MAX];
ssize_t size = readlink(path.c_str(), buffer, MPD_PATH_MAX); ssize_t size = readlink(path.c_str(), buffer, MPD_PATH_MAX);
if (size < 0) if (size < 0)
return AllocatedPath::Null(); return nullptr;
if (size_t(size) >= MPD_PATH_MAX) { if (size_t(size) >= MPD_PATH_MAX) {
errno = ENOMEM; errno = ENOMEM;
return AllocatedPath::Null(); return nullptr;
} }
buffer[size] = '\0'; buffer[size] = '\0';
return AllocatedPath::FromFS(buffer); return AllocatedPath::FromFS(buffer);
......
...@@ -109,7 +109,7 @@ SafePathFromFS(PathTraitsFS::const_pointer_type dir) ...@@ -109,7 +109,7 @@ SafePathFromFS(PathTraitsFS::const_pointer_type dir)
{ {
if (IsValidPathString(dir) && IsValidDir(dir)) if (IsValidPathString(dir) && IsValidDir(dir))
return AllocatedPath::FromFS(dir); return AllocatedPath::FromFS(dir);
return AllocatedPath::Null(); return nullptr;
} }
#endif #endif
...@@ -120,7 +120,7 @@ static AllocatedPath GetStandardDir(int folder_id) ...@@ -120,7 +120,7 @@ static AllocatedPath GetStandardDir(int folder_id)
auto ret = SHGetFolderPath(nullptr, folder_id | CSIDL_FLAG_DONT_VERIFY, auto ret = SHGetFolderPath(nullptr, folder_id | CSIDL_FLAG_DONT_VERIFY,
nullptr, SHGFP_TYPE_CURRENT, dir.data()); nullptr, SHGFP_TYPE_CURRENT, dir.data());
if (FAILED(ret)) if (FAILED(ret))
return AllocatedPath::Null(); return nullptr;
return SafePathFromFS(dir.data()); return SafePathFromFS(dir.data());
} }
#endif #endif
...@@ -185,7 +185,7 @@ ParseConfigLine(char *line, const char *dir_name, AllocatedPath &result_dir) ...@@ -185,7 +185,7 @@ ParseConfigLine(char *line, const char *dir_name, AllocatedPath &result_dir)
// build the result path // build the result path
const char *path = line; const char *path = line;
auto result = AllocatedPath::Null(); AllocatedPath result = nullptr;
if (home_relative) { if (home_relative) {
auto home = GetHomeDir(); auto home = GetHomeDir();
if (home.IsNull()) if (home.IsNull())
...@@ -205,7 +205,7 @@ ParseConfigLine(char *line, const char *dir_name, AllocatedPath &result_dir) ...@@ -205,7 +205,7 @@ ParseConfigLine(char *line, const char *dir_name, AllocatedPath &result_dir)
static AllocatedPath static AllocatedPath
GetUserDir(const char *name) noexcept GetUserDir(const char *name) noexcept
try { try {
auto result = AllocatedPath::Null(); AllocatedPath result = nullptr;
auto config_dir = GetUserConfigDir(); auto config_dir = GetUserConfigDir();
if (config_dir.IsNull()) if (config_dir.IsNull())
return result; return result;
...@@ -218,7 +218,7 @@ try { ...@@ -218,7 +218,7 @@ try {
return result; return result;
return result; return result;
} catch (const std::exception &e) { } catch (const std::exception &e) {
return AllocatedPath::Null(); return nullptr;
} }
#endif #endif
...@@ -242,9 +242,9 @@ GetUserConfigDir() noexcept ...@@ -242,9 +242,9 @@ GetUserConfigDir() noexcept
return fallback; return fallback;
} }
return AllocatedPath::Null(); return nullptr;
#else #else
return AllocatedPath::Null(); return nullptr;
#endif #endif
} }
...@@ -258,7 +258,7 @@ GetUserMusicDir() noexcept ...@@ -258,7 +258,7 @@ GetUserMusicDir() noexcept
#elif defined(ANDROID) #elif defined(ANDROID)
return Environment::getExternalStoragePublicDirectory("Music"); return Environment::getExternalStoragePublicDirectory("Music");
#else #else
return AllocatedPath::Null(); return nullptr;
#endif #endif
} }
...@@ -279,11 +279,11 @@ GetUserCacheDir() noexcept ...@@ -279,11 +279,11 @@ GetUserCacheDir() noexcept
return fallback; return fallback;
} }
return AllocatedPath::Null(); return nullptr;
#elif defined(ANDROID) #elif defined(ANDROID)
return context->GetCacheDir(Java::GetEnv()); return context->GetCacheDir(Java::GetEnv());
#else #else
return AllocatedPath::Null(); return nullptr;
#endif #endif
} }
...@@ -303,11 +303,11 @@ GetAppBaseDir() noexcept ...@@ -303,11 +303,11 @@ GetAppBaseDir() noexcept
// Check for error // Check for error
if (ret == 0) if (ret == 0)
return AllocatedPath::Null(); return nullptr;
// Check for truncation // Check for truncation
if (ret == app.size() && GetLastError() == ERROR_INSUFFICIENT_BUFFER) if (ret == app.size() && GetLastError() == ERROR_INSUFFICIENT_BUFFER)
return AllocatedPath::Null(); return nullptr;
auto app_path = AllocatedPath::FromFS(app.data()); auto app_path = AllocatedPath::FromFS(app.data());
return app_path.GetDirectoryName().GetDirectoryName(); return app_path.GetDirectoryName().GetDirectoryName();
...@@ -326,7 +326,7 @@ GetHomeDir() noexcept ...@@ -326,7 +326,7 @@ GetHomeDir() noexcept
if (pw.ReadByUid(getuid())) if (pw.ReadByUid(getuid()))
return SafePathFromFS(pw->pw_dir); return SafePathFromFS(pw->pw_dir);
#endif #endif
return AllocatedPath::Null(); return nullptr;
} }
AllocatedPath AllocatedPath
...@@ -340,7 +340,7 @@ GetHomeDir(const char *user_name) noexcept ...@@ -340,7 +340,7 @@ GetHomeDir(const char *user_name) noexcept
if (pw.ReadByName(user_name)) if (pw.ReadByName(user_name))
return SafePathFromFS(pw->pw_dir); return SafePathFromFS(pw->pw_dir);
#endif #endif
return AllocatedPath::Null(); return nullptr;
} }
#endif #endif
...@@ -175,7 +175,7 @@ cdio_detect_device(void) ...@@ -175,7 +175,7 @@ cdio_detect_device(void)
char **devices = cdio_get_devices_with_cap(nullptr, CDIO_FS_AUDIO, char **devices = cdio_get_devices_with_cap(nullptr, CDIO_FS_AUDIO,
false); false);
if (devices == nullptr) if (devices == nullptr)
return AllocatedPath::Null(); return nullptr;
AllocatedPath path = AllocatedPath::FromFS(devices[0]); AllocatedPath path = AllocatedPath::FromFS(devices[0]);
cdio_free_device_list(devices); cdio_free_device_list(devices);
......
...@@ -57,7 +57,7 @@ Java::File::ToAbsolutePath(JNIEnv *env, jobject _file) ...@@ -57,7 +57,7 @@ Java::File::ToAbsolutePath(JNIEnv *env, jobject _file)
const jstring path = getAbsolutePath(env, file); const jstring path = getAbsolutePath(env, file);
if (path == nullptr) { if (path == nullptr) {
env->ExceptionClear(); env->ExceptionClear();
return AllocatedPath::Null(); return nullptr;
} }
Java::String path2(env, path); Java::String path2(env, path);
......
...@@ -50,7 +50,7 @@ class RecorderOutput final : AudioOutput { ...@@ -50,7 +50,7 @@ class RecorderOutput final : AudioOutput {
/** /**
* The destination file name. * The destination file name.
*/ */
AllocatedPath path = AllocatedPath::Null(); AllocatedPath path = nullptr;
/** /**
* A string that will be used with FormatTag() to build the * A string that will be used with FormatTag() to build the
...@@ -298,7 +298,7 @@ RecorderOutput::SendTag(const Tag &tag) ...@@ -298,7 +298,7 @@ RecorderOutput::SendTag(const Tag &tag)
AtScopeExit(p) { free(p); }; AtScopeExit(p) { free(p); };
AllocatedPath new_path = AllocatedPath::Null(); AllocatedPath new_path = nullptr;
try { try {
new_path = ParsePath(p); new_path = ParsePath(p);
......
...@@ -316,7 +316,7 @@ CompositeStorage::MapFS(const char *uri) const noexcept ...@@ -316,7 +316,7 @@ CompositeStorage::MapFS(const char *uri) const noexcept
auto f = FindStorage(uri); auto f = FindStorage(uri);
if (f.directory->storage == nullptr) if (f.directory->storage == nullptr)
return AllocatedPath::Null(); return nullptr;
return f.directory->storage->MapFS(f.uri); return f.directory->storage->MapFS(f.uri);
} }
......
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
AllocatedPath AllocatedPath
Storage::MapFS(gcc_unused const char *uri_utf8) const noexcept Storage::MapFS(gcc_unused const char *uri_utf8) const noexcept
{ {
return AllocatedPath::Null(); return nullptr;
} }
AllocatedPath AllocatedPath
......
...@@ -66,7 +66,7 @@ public: ...@@ -66,7 +66,7 @@ public:
/** /**
* Map the given relative URI to a local file path. Returns * Map the given relative URI to a local file path. Returns
* AllocatedPath::Null() on error or if this storage does not * nullptr on error or if this storage does not
* support local files. * support local files.
*/ */
gcc_pure gcc_pure
......
...@@ -124,7 +124,7 @@ LocalStorage::MapFS(const char *uri_utf8) const noexcept ...@@ -124,7 +124,7 @@ LocalStorage::MapFS(const char *uri_utf8) const noexcept
try { try {
return MapFSOrThrow(uri_utf8); return MapFSOrThrow(uri_utf8);
} catch (...) { } catch (...) {
return AllocatedPath::Null(); return nullptr;
} }
} }
......
...@@ -54,7 +54,7 @@ static uid_t user_uid = (uid_t)-1; ...@@ -54,7 +54,7 @@ static uid_t user_uid = (uid_t)-1;
static gid_t user_gid = (gid_t)-1; static gid_t user_gid = (gid_t)-1;
/** the absolute path of the pidfile */ /** the absolute path of the pidfile */
static AllocatedPath pidfile = AllocatedPath::Null(); static AllocatedPath pidfile = nullptr;
/* whether "group" conf. option was given */ /* whether "group" conf. option was given */
static bool had_group = false; static bool had_group = false;
...@@ -251,7 +251,7 @@ daemonize_finish(void) ...@@ -251,7 +251,7 @@ daemonize_finish(void)
{ {
if (!pidfile.IsNull()) { if (!pidfile.IsNull()) {
unlink(pidfile.c_str()); unlink(pidfile.c_str());
pidfile = AllocatedPath::Null(); pidfile = nullptr;
} }
free(user_name); free(user_name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment