summaryrefslogtreecommitdiff
path: root/asl/io/print.cpp
blob: 5b48eef853136663432d8a48817971b8813e4b80 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Copyright 2025 Steven Le Rouzic
//
// SPDX-License-Identifier: BSD-3-Clause

#include "asl/io/print.hpp"

#include <cstdio>

// @Todo Optimize this, maybe make buffered
class ConsoleWriter : public asl::Writer
{
    FILE* m_handle;

public:
    explicit ConsoleWriter(FILE* handle)
        : m_handle{handle}
    {}

    void write(asl::span<const asl::byte> s) override
    {
        fwrite(s.data(), 1, static_cast<size_t>(s.size()), m_handle);
    }
};

asl::Writer* asl::print_internals::get_stdout_writer()
{
    static ConsoleWriter s_writer{stdout};
    return &s_writer;
}

asl::Writer* asl::print_internals::get_stderr_writer()
{
    static ConsoleWriter s_writer{stderr};
    return &s_writer;
}