.github
android
build
doc
python
src
android
apple
archive
client
command
config
db
decoder
encoder
event
filter
fs
input
io
java
lib
alsa
avahi
cdio
chromaprint
crypto
curl
dbus
expat
ffmpeg
fmt
AudioFormatFormatter.hxx
ExceptionFormatter.hxx
PathFormatter.hxx
SystemError.cxx
SystemError.hxx
ToBuffer.hxx
meson.build
gcrypt
icu
jack
nfs
oss
pcre
pipewire
pulse
smbclient
sndio
sqlite
systemd
upnp
xiph
yajl
zlib
mixer
neighbor
net
output
pcm
player
playlist
protocol
queue
song
sticker
storage
system
tag
thread
time
unix
util
win32
zeroconf
BulkEdit.hxx
Chrono.hxx
CommandLine.cxx
CommandLine.hxx
ConsumeMode.cxx
ConsumeMode.hxx
GitVersion.cxx
GitVersion.hxx
Idle.cxx
Idle.hxx
IdleFlags.cxx
IdleFlags.hxx
Instance.cxx
Instance.hxx
Listen.cxx
Listen.hxx
LocateUri.cxx
LocateUri.hxx
Log.cxx
Log.hxx
LogBackend.cxx
LogBackend.hxx
LogInit.cxx
LogInit.hxx
LogLevel.hxx
Main.cxx
Main.hxx
Mapper.cxx
Mapper.hxx
MusicBuffer.cxx
MusicBuffer.hxx
MusicChunk.cxx
MusicChunk.hxx
MusicChunkPtr.cxx
MusicChunkPtr.hxx
MusicPipe.cxx
MusicPipe.hxx
Partition.cxx
Partition.hxx
Permission.cxx
Permission.hxx
PlaylistDatabase.cxx
PlaylistDatabase.hxx
PlaylistError.cxx
PlaylistError.hxx
PlaylistFile.cxx
PlaylistFile.hxx
PlaylistPrint.cxx
PlaylistPrint.hxx
PlaylistSave.cxx
PlaylistSave.hxx
PluginUnavailable.hxx
RemoteTagCache.cxx
RemoteTagCache.hxx
RemoteTagCacheHandler.hxx
ReplayGainMode.cxx
ReplayGainMode.hxx
SingleMode.cxx
SingleMode.hxx
SongLoader.cxx
SongLoader.hxx
SongPrint.cxx
SongPrint.hxx
SongSave.cxx
SongSave.hxx
SongUpdate.cxx
StateFile.cxx
StateFile.hxx
StateFileConfig.cxx
StateFileConfig.hxx
Stats.cxx
Stats.hxx
TagAny.cxx
TagAny.hxx
TagArchive.cxx
TagArchive.hxx
TagFile.cxx
TagFile.hxx
TagPrint.cxx
TagPrint.hxx
TagSave.cxx
TagSave.hxx
TagStream.cxx
TagStream.hxx
TimePrint.cxx
TimePrint.hxx
ls.cxx
ls.hxx
open.h
subprojects
systemd
test
win32
.clang-format
.gitignore
AUTHORS
COPYING
NEWS
README.md
meson.build
meson_options.txt
mpd.svg
valgrind.suppressions
123 lines
3.7 KiB
C++
123 lines
3.7 KiB
C++
/*
|
|
* Copyright 2022 Max Kellermann <max.kellermann@gmail.com>
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted provided that the following conditions
|
|
* are met:
|
|
*
|
|
* - Redistributions of source code must retain the above copyright
|
|
* notice, this list of conditions and the following disclaimer.
|
|
*
|
|
* - Redistributions in binary form must reproduce the above copyright
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
* documentation and/or other materials provided with the
|
|
* distribution.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
* FOUNDATION OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
|
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
|
|
* OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include "system/Error.hxx" // IWYU pragma: export
|
|
|
|
#include <fmt/core.h>
|
|
#if FMT_VERSION >= 80000 && FMT_VERSION < 90000
|
|
#include <fmt/format.h>
|
|
#endif
|
|
|
|
[[nodiscard]] [[gnu::pure]]
|
|
std::system_error
|
|
VFmtSystemError(std::error_code code,
|
|
fmt::string_view format_str, fmt::format_args args) noexcept;
|
|
|
|
template<typename S, typename... Args>
|
|
[[nodiscard]] [[gnu::pure]]
|
|
std::system_error
|
|
FmtSystemError(std::error_code code,
|
|
const S &format_str, Args&&... args) noexcept
|
|
{
|
|
#if FMT_VERSION >= 90000
|
|
return VFmtSystemError(code, format_str,
|
|
fmt::make_format_args(args...));
|
|
#else
|
|
return VFmtSystemError(code, fmt::to_string_view(format_str),
|
|
fmt::make_args_checked<Args...>(format_str,
|
|
args...));
|
|
#endif
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
|
|
[[nodiscard]] [[gnu::pure]]
|
|
std::system_error
|
|
VFmtLastError(DWORD code,
|
|
fmt::string_view format_str, fmt::format_args args) noexcept;
|
|
|
|
template<typename S, typename... Args>
|
|
[[nodiscard]] [[gnu::pure]]
|
|
std::system_error
|
|
FmtLastError(DWORD code,
|
|
const S &format_str, Args&&... args) noexcept
|
|
{
|
|
#if FMT_VERSION >= 90000
|
|
return VFmtLastError(code, format_str,
|
|
fmt::make_format_args(args...));
|
|
#else
|
|
return VFmtLastError(code, fmt::to_string_view(format_str),
|
|
fmt::make_args_checked<Args...>(format_str,
|
|
args...));
|
|
#endif
|
|
}
|
|
|
|
template<typename S, typename... Args>
|
|
[[nodiscard]] [[gnu::pure]]
|
|
std::system_error
|
|
FmtLastError(const S &format_str, Args&&... args) noexcept
|
|
{
|
|
return FmtLastError(GetLastError(),
|
|
format_str, std::forward<Args>(args)...);
|
|
}
|
|
|
|
#endif // _WIN32
|
|
|
|
template<typename S, typename... Args>
|
|
[[nodiscard]] [[gnu::pure]]
|
|
std::system_error
|
|
FmtErrno(int code, const S &format_str, Args&&... args) noexcept
|
|
{
|
|
return FmtSystemError(std::error_code(code, ErrnoCategory()),
|
|
format_str, std::forward<Args>(args)...);
|
|
}
|
|
|
|
template<typename S, typename... Args>
|
|
[[nodiscard]] [[gnu::pure]]
|
|
std::system_error
|
|
FmtErrno(const S &format_str, Args&&... args) noexcept
|
|
{
|
|
return FmtErrno(errno, format_str, std::forward<Args>(args)...);
|
|
}
|
|
|
|
template<typename S, typename... Args>
|
|
[[nodiscard]] [[gnu::pure]]
|
|
std::system_error
|
|
FmtFileNotFound(const S &format_str, Args&&... args) noexcept
|
|
{
|
|
#ifdef _WIN32
|
|
return FmtLastError(DWORD{ERROR_FILE_NOT_FOUND},
|
|
format_str, std::forward<Args>(args)...);
|
|
#else
|
|
return FmtErrno(ENOENT, format_str, std::forward<Args>(args)...);
|
|
#endif
|
|
}
|