1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +00:00

AK: Add out() and warn() streams that forward to stdout and stderr

Our C++ code generator tools have been relying on host-side dbg() being
forwarded to stdout until now. Now they use out() instead.

Hopefully this will make it easier and more enticing to use streams in
userspace programs as well. :^)
This commit is contained in:
Andreas Kling 2020-04-06 10:12:10 +02:00
parent 63b11e094d
commit 0d48fb9a87
6 changed files with 219 additions and 176 deletions

View file

@ -34,6 +34,10 @@
# include <Kernel/Thread.h>
#endif
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
#include <stdio.h>
#endif
namespace AK {
const LogStream& operator<<(const LogStream& stream, const String& value)
@ -163,4 +167,20 @@ DebugLogStream::~DebugLogStream()
write(&newline, 1);
}
#if !defined(KERNEL) && !defined(BOOTSTRAPPER)
StdLogStream::~StdLogStream()
{
char newline = '\n';
write(&newline, 1);
}
void StdLogStream::write(const char* characters, int length) const
{
if (::write(m_fd, characters, length) < 0) {
perror("StdLogStream::write");
ASSERT_NOT_REACHED();
}
}
#endif
}