mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:38:12 +00:00
Kernel: Make a bunch of "char const* to_string()" return StringView
This commit is contained in:
parent
f35108fc31
commit
af46f2214c
4 changed files with 34 additions and 33 deletions
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <AK/StringView.h>
|
||||||
#include <AK/Types.h>
|
#include <AK/Types.h>
|
||||||
#include <AK/Userspace.h>
|
#include <AK/Userspace.h>
|
||||||
|
|
||||||
|
@ -206,19 +207,19 @@ enum Function {
|
||||||
__Count
|
__Count
|
||||||
};
|
};
|
||||||
|
|
||||||
constexpr const char* to_string(Function function)
|
constexpr StringView to_string(Function function)
|
||||||
{
|
{
|
||||||
switch (function) {
|
switch (function) {
|
||||||
#undef __ENUMERATE_SYSCALL
|
#undef __ENUMERATE_SYSCALL
|
||||||
#define __ENUMERATE_SYSCALL(sys_call, needs_lock) \
|
#define __ENUMERATE_SYSCALL(sys_call, needs_lock) \
|
||||||
case SC_##sys_call: \
|
case SC_##sys_call: \
|
||||||
return #sys_call;
|
return #sys_call##sv;
|
||||||
ENUMERATE_SYSCALLS(__ENUMERATE_SYSCALL)
|
ENUMERATE_SYSCALLS(__ENUMERATE_SYSCALL)
|
||||||
#undef __ENUMERATE_SYSCALL
|
#undef __ENUMERATE_SYSCALL
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return "Unknown";
|
return "Unknown"sv;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef __serenity__
|
#ifdef __serenity__
|
||||||
|
|
|
@ -51,17 +51,17 @@ public:
|
||||||
Connecting
|
Connecting
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* to_string(SetupState setup_state)
|
static StringView to_string(SetupState setup_state)
|
||||||
{
|
{
|
||||||
switch (setup_state) {
|
switch (setup_state) {
|
||||||
case SetupState::Unstarted:
|
case SetupState::Unstarted:
|
||||||
return "Unstarted";
|
return "Unstarted"sv;
|
||||||
case SetupState::InProgress:
|
case SetupState::InProgress:
|
||||||
return "InProgress";
|
return "InProgress"sv;
|
||||||
case SetupState::Completed:
|
case SetupState::Completed:
|
||||||
return "Completed";
|
return "Completed"sv;
|
||||||
default:
|
default:
|
||||||
return "None";
|
return "None"sv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -28,19 +28,19 @@ public:
|
||||||
Passive,
|
Passive,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* to_string(Direction direction)
|
static StringView to_string(Direction direction)
|
||||||
{
|
{
|
||||||
switch (direction) {
|
switch (direction) {
|
||||||
case Direction::Unspecified:
|
case Direction::Unspecified:
|
||||||
return "Unspecified";
|
return "Unspecified"sv;
|
||||||
case Direction::Outgoing:
|
case Direction::Outgoing:
|
||||||
return "Outgoing";
|
return "Outgoing"sv;
|
||||||
case Direction::Incoming:
|
case Direction::Incoming:
|
||||||
return "Incoming";
|
return "Incoming"sv;
|
||||||
case Direction::Passive:
|
case Direction::Passive:
|
||||||
return "Passive";
|
return "Passive"sv;
|
||||||
default:
|
default:
|
||||||
return "None";
|
return "None"sv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -58,31 +58,31 @@ public:
|
||||||
TimeWait,
|
TimeWait,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* to_string(State state)
|
static StringView to_string(State state)
|
||||||
{
|
{
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case State::Closed:
|
case State::Closed:
|
||||||
return "Closed";
|
return "Closed"sv;
|
||||||
case State::Listen:
|
case State::Listen:
|
||||||
return "Listen";
|
return "Listen"sv;
|
||||||
case State::SynSent:
|
case State::SynSent:
|
||||||
return "SynSent";
|
return "SynSent"sv;
|
||||||
case State::SynReceived:
|
case State::SynReceived:
|
||||||
return "SynReceived";
|
return "SynReceived"sv;
|
||||||
case State::Established:
|
case State::Established:
|
||||||
return "Established";
|
return "Established"sv;
|
||||||
case State::CloseWait:
|
case State::CloseWait:
|
||||||
return "CloseWait";
|
return "CloseWait"sv;
|
||||||
case State::LastAck:
|
case State::LastAck:
|
||||||
return "LastAck";
|
return "LastAck"sv;
|
||||||
case State::FinWait1:
|
case State::FinWait1:
|
||||||
return "FinWait1";
|
return "FinWait1"sv;
|
||||||
case State::FinWait2:
|
case State::FinWait2:
|
||||||
return "FinWait2";
|
return "FinWait2"sv;
|
||||||
case State::Closing:
|
case State::Closing:
|
||||||
return "Closing";
|
return "Closing"sv;
|
||||||
case State::TimeWait:
|
case State::TimeWait:
|
||||||
return "TimeWait";
|
return "TimeWait"sv;
|
||||||
default:
|
default:
|
||||||
return "None";
|
return "None";
|
||||||
}
|
}
|
||||||
|
@ -96,19 +96,19 @@ public:
|
||||||
RetransmitTimeout,
|
RetransmitTimeout,
|
||||||
};
|
};
|
||||||
|
|
||||||
static const char* to_string(Error error)
|
static StringView to_string(Error error)
|
||||||
{
|
{
|
||||||
switch (error) {
|
switch (error) {
|
||||||
case Error::None:
|
case Error::None:
|
||||||
return "None";
|
return "None"sv;
|
||||||
case Error::FINDuringConnect:
|
case Error::FINDuringConnect:
|
||||||
return "FINDuringConnect";
|
return "FINDuringConnect"sv;
|
||||||
case Error::RSTDuringConnect:
|
case Error::RSTDuringConnect:
|
||||||
return "RSTDuringConnect";
|
return "RSTDuringConnect"sv;
|
||||||
case Error::UnexpectedFlagsDuringConnect:
|
case Error::UnexpectedFlagsDuringConnect:
|
||||||
return "UnexpectedFlagsDuringConnect";
|
return "UnexpectedFlagsDuringConnect"sv;
|
||||||
default:
|
default:
|
||||||
return "Invalid";
|
return "Invalid"sv;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
if (arg[0] > Syscall::Function::__Count) {
|
if (arg[0] > Syscall::Function::__Count) {
|
||||||
for (int sc = 0; sc < Syscall::Function::__Count; ++sc) {
|
for (int sc = 0; sc < Syscall::Function::__Count; ++sc) {
|
||||||
if (strcmp(Syscall::to_string((Syscall::Function)sc), (char*)arg[0]) == 0) {
|
if (Syscall::to_string((Syscall::Function)sc) == (char const*)arg[0]) {
|
||||||
arg[0] = sc;
|
arg[0] = sc;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue