2021-01-10 12:46:17 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-01-10 12:46:17 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AK/Format.h>
|
2021-03-12 16:29:37 +00:00
|
|
|
#include <errno.h>
|
2021-01-10 12:46:17 +00:00
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
class OSError {
|
|
|
|
public:
|
|
|
|
explicit OSError(int error)
|
|
|
|
: m_error(error)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
int error() const { return m_error; }
|
|
|
|
const char* string() const { return strerror(m_error); }
|
|
|
|
|
|
|
|
private:
|
|
|
|
int m_error { 0 };
|
|
|
|
};
|
|
|
|
|
|
|
|
template<>
|
|
|
|
struct Formatter<OSError> : Formatter<StringView> {
|
|
|
|
void format(FormatBuilder& builder, const OSError& value)
|
|
|
|
{
|
|
|
|
Formatter<StringView>::format(builder, value.string());
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
using AK::OSError;
|