fs/Traits: add macro PATH_LITERAL()
This commit is contained in:
parent
44565e22a0
commit
39c9669445
@ -66,12 +66,12 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#ifdef WIN32
|
#ifdef WIN32
|
||||||
#define CONFIG_FILE_LOCATION "mpd\\mpd.conf"
|
#define CONFIG_FILE_LOCATION PATH_LITERAL("mpd\\mpd.conf")
|
||||||
#define APP_CONFIG_FILE_LOCATION "conf\\mpd.conf"
|
#define APP_CONFIG_FILE_LOCATION PATH_LITERAL("conf\\mpd.conf")
|
||||||
#else
|
#else
|
||||||
#define USER_CONFIG_FILE_LOCATION1 ".mpdconf"
|
#define USER_CONFIG_FILE_LOCATION1 PATH_LITERAL(".mpdconf")
|
||||||
#define USER_CONFIG_FILE_LOCATION2 ".mpd/mpd.conf"
|
#define USER_CONFIG_FILE_LOCATION2 PATH_LITERAL(".mpd/mpd.conf")
|
||||||
#define USER_CONFIG_FILE_LOCATION_XDG "mpd/mpd.conf"
|
#define USER_CONFIG_FILE_LOCATION_XDG PATH_LITERAL("mpd/mpd.conf")
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static constexpr OptionDef opt_kill(
|
static constexpr OptionDef opt_kill(
|
||||||
|
@ -174,7 +174,8 @@ LoadPlaylistFileInfo(PlaylistInfo &info,
|
|||||||
|
|
||||||
const auto *const name_fs_str = name_fs.c_str();
|
const auto *const name_fs_str = name_fs.c_str();
|
||||||
const auto *const name_fs_end =
|
const auto *const name_fs_end =
|
||||||
FindStringSuffix(name_fs_str, PLAYLIST_FILE_SUFFIX);
|
FindStringSuffix(name_fs_str,
|
||||||
|
PATH_LITERAL(PLAYLIST_FILE_SUFFIX));
|
||||||
if (name_fs_end == nullptr)
|
if (name_fs_end == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -59,7 +59,8 @@ CreateConfiguredDatabase(EventLoop &loop, DatabaseListener &listener,
|
|||||||
if (cache_dir.IsNull())
|
if (cache_dir.IsNull())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
|
||||||
const auto db_file = AllocatedPath::Build(cache_dir, "mpd.db");
|
const auto db_file = AllocatedPath::Build(cache_dir,
|
||||||
|
PATH_LITERAL("mpd.db"));
|
||||||
const auto db_file_utf8 = db_file.ToUTF8();
|
const auto db_file_utf8 = db_file.ToUTF8();
|
||||||
if (db_file_utf8.empty())
|
if (db_file_utf8.empty())
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -41,12 +41,12 @@ namespace FOpenMode {
|
|||||||
/**
|
/**
|
||||||
* Open mode for writing text files.
|
* Open mode for writing text files.
|
||||||
*/
|
*/
|
||||||
constexpr PathTraitsFS::const_pointer WriteText = "w";
|
constexpr PathTraitsFS::const_pointer WriteText = PATH_LITERAL("w");
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open mode for appending text files.
|
* Open mode for appending text files.
|
||||||
*/
|
*/
|
||||||
constexpr PathTraitsFS::const_pointer AppendText = "a";
|
constexpr PathTraitsFS::const_pointer AppendText = PATH_LITERAL("a");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
|
||||||
|
#define PATH_LITERAL(s) (s)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class describes the nature of a native filesystem path.
|
* This class describes the nature of a native filesystem path.
|
||||||
*/
|
*/
|
||||||
@ -48,7 +50,7 @@ struct PathTraitsFS {
|
|||||||
static constexpr value_type SEPARATOR = '/';
|
static constexpr value_type SEPARATOR = '/';
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static constexpr const_pointer CURRENT_DIRECTORY = ".";
|
static constexpr const_pointer CURRENT_DIRECTORY = PATH_LITERAL(".");
|
||||||
|
|
||||||
static constexpr bool IsSeparator(value_type ch) {
|
static constexpr bool IsSeparator(value_type ch) {
|
||||||
return
|
return
|
||||||
|
@ -103,7 +103,7 @@ ape_scan_internal(FILE *fp, ApeTagCallback callback)
|
|||||||
bool
|
bool
|
||||||
tag_ape_scan(Path path_fs, ApeTagCallback callback)
|
tag_ape_scan(Path path_fs, ApeTagCallback callback)
|
||||||
{
|
{
|
||||||
FILE *fp = FOpen(path_fs, "rb");
|
FILE *fp = FOpen(path_fs, PATH_LITERAL("rb"));
|
||||||
if (fp == nullptr)
|
if (fp == nullptr)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -521,7 +521,7 @@ tag_id3_riff_aiff_load(FILE *file)
|
|||||||
struct id3_tag *
|
struct id3_tag *
|
||||||
tag_id3_load(Path path_fs, Error &error)
|
tag_id3_load(Path path_fs, Error &error)
|
||||||
{
|
{
|
||||||
FILE *file = FOpen(path_fs, "rb");
|
FILE *file = FOpen(path_fs, PATH_LITERAL("rb"));
|
||||||
if (file == nullptr) {
|
if (file == nullptr) {
|
||||||
error.FormatErrno("Failed to open file %s", path_fs.c_str());
|
error.FormatErrno("Failed to open file %s", path_fs.c_str());
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
@ -71,7 +71,7 @@ daemonize_kill(void)
|
|||||||
if (pidfile.IsNull())
|
if (pidfile.IsNull())
|
||||||
FatalError("no pid_file specified in the config file");
|
FatalError("no pid_file specified in the config file");
|
||||||
|
|
||||||
fp = FOpen(pidfile, "r");
|
fp = FOpen(pidfile, PATH_LITERAL("r"));
|
||||||
if (fp == nullptr) {
|
if (fp == nullptr) {
|
||||||
const std::string utf8 = pidfile.ToUTF8();
|
const std::string utf8 = pidfile.ToUTF8();
|
||||||
FormatFatalSystemError("Unable to open pid file \"%s\"",
|
FormatFatalSystemError("Unable to open pid file \"%s\"",
|
||||||
|
@ -37,7 +37,7 @@ public:
|
|||||||
if (path.IsNull())
|
if (path.IsNull())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
file = FOpen(path, "w");
|
file = FOpen(path, FOpenMode::WriteText);
|
||||||
if (file == nullptr) {
|
if (file == nullptr) {
|
||||||
const std::string utf8 = path.ToUTF8();
|
const std::string utf8 = path.ToUTF8();
|
||||||
FormatFatalSystemError("Failed to create pid file \"%s\"",
|
FormatFatalSystemError("Failed to create pid file \"%s\"",
|
||||||
|
Loading…
Reference in New Issue
Block a user