mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 05:57:44 +00:00
Add a String::format() and use that in place of ksprintf() in the Kernel.
You're never gonna be right 100% of the time when guessing how much buffer space you need. This avoids having to make that type of decision in a bunch of cases. :^)
This commit is contained in:
parent
e9b948103d
commit
027d26cd5d
11 changed files with 40 additions and 34 deletions
|
@ -205,15 +205,11 @@ char* ELFLoader::symbol_ptr(const char* name)
|
|||
bool ELFLoader::allocate_section(LinearAddress laddr, size_t size, size_t alignment, bool is_readable, bool is_writable)
|
||||
{
|
||||
ASSERT(alloc_section_hook);
|
||||
char namebuf[16];
|
||||
ksprintf(namebuf, "elf-alloc-%s%s", is_readable ? "r" : "", is_writable ? "w" : "");
|
||||
return alloc_section_hook(laddr, size, alignment, is_readable, is_writable, namebuf);
|
||||
return alloc_section_hook(laddr, size, alignment, is_readable, is_writable, String::format("elf-alloc-%s%s", is_readable ? "r" : "", is_writable ? "w" : ""));
|
||||
}
|
||||
|
||||
bool ELFLoader::map_section(LinearAddress laddr, size_t size, size_t alignment, size_t offset_in_image, bool is_readable, bool is_writable)
|
||||
{
|
||||
ASSERT(alloc_section_hook);
|
||||
char namebuf[16];
|
||||
ksprintf(namebuf, "elf-map-%s%s", is_readable ? "r" : "", is_writable ? "w" : "");
|
||||
return map_section_hook(laddr, size, alignment, offset_in_image, is_readable, is_writable, namebuf);
|
||||
return map_section_hook(laddr, size, alignment, offset_in_image, is_readable, is_writable, String::format("elf-map-%s%s", is_readable ? "r" : "", is_writable ? "w" : ""));
|
||||
}
|
||||
|
|
|
@ -292,16 +292,10 @@ String FileDescriptor::absolute_path()
|
|||
Stopwatch sw("absolute_path");
|
||||
if (is_tty())
|
||||
return tty()->tty_name();
|
||||
if (is_fifo()) {
|
||||
char buf[32];
|
||||
ksprintf(buf, "fifo:%x", m_fifo.ptr());
|
||||
return buf;
|
||||
}
|
||||
if (is_character_device()) {
|
||||
char buf[128];
|
||||
ksprintf(buf, "device:%u,%u (%s)", m_device->major(), m_device->minor(), m_device->class_name());
|
||||
return buf;
|
||||
}
|
||||
if (is_fifo())
|
||||
return String::format("fifo:%x", m_fifo.ptr());
|
||||
if (is_character_device())
|
||||
return String::format("device:%u,%u (%s)", m_device->major(), m_device->minor(), m_device->class_name());
|
||||
ASSERT(m_inode);
|
||||
return VFS::the().absolute_path(*m_inode);
|
||||
}
|
||||
|
|
|
@ -14,9 +14,7 @@ MasterPTY::~MasterPTY()
|
|||
|
||||
String MasterPTY::pts_name() const
|
||||
{
|
||||
char buffer[32];
|
||||
ksprintf(buffer, "/dev/pts/%u", m_index);
|
||||
return buffer;
|
||||
return String::format("/dev/pts/%u", m_index);
|
||||
}
|
||||
|
||||
ssize_t MasterPTY::read(Process&, byte* buffer, size_t size)
|
||||
|
|
|
@ -153,9 +153,7 @@ ByteBuffer procfs$pid_cwd(Process& process)
|
|||
void ProcFS::add_process(Process& process)
|
||||
{
|
||||
InterruptDisabler disabler;
|
||||
char buf[16];
|
||||
ksprintf(buf, "%d", process.pid());
|
||||
auto dir = add_file(create_directory(buf));
|
||||
auto dir = add_file(create_directory(String::format("%d", process.pid())));
|
||||
m_pid2inode.set(process.pid(), dir.index());
|
||||
add_file(create_generated_file("vm", [&process] (SynthFSInode&) { return procfs$pid_vm(process); }), dir.index());
|
||||
add_file(create_generated_file("vmo", [&process] (SynthFSInode&) { return procfs$pid_vmo(process); }), dir.index());
|
||||
|
|
|
@ -19,9 +19,7 @@ SlavePTY::~SlavePTY()
|
|||
|
||||
String SlavePTY::tty_name() const
|
||||
{
|
||||
char buffer[32];
|
||||
ksprintf(buffer, "/dev/pts/%u", m_index);
|
||||
return buffer;
|
||||
return String::format("/dev/pts/%u", m_index);
|
||||
}
|
||||
|
||||
void SlavePTY::on_master_write(const byte* buffer, size_t size)
|
||||
|
|
|
@ -508,9 +508,7 @@ void VirtualConsole::on_tty_write(const byte* data, size_t size)
|
|||
|
||||
String VirtualConsole::tty_name() const
|
||||
{
|
||||
char buf[16];
|
||||
ksprintf(buf, "/dev/tty%u", m_index);
|
||||
return String(buf);
|
||||
return String::format("/dev/tty%u", m_index);
|
||||
}
|
||||
|
||||
void VirtualConsole::set_vga_start_row(word row)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue