Luna/libluna/include/luna/Format.h

20 lines
885 B
C
Raw Normal View History

2022-11-19 11:30:36 +00:00
#pragma once
#include <luna/Attributes.h>
#include <luna/Result.h>
2022-11-19 11:30:36 +00:00
#include <stdarg.h>
2022-11-19 15:13:25 +00:00
typedef Result<void> (*callback_t)(char, void*);
typedef void (*pure_callback_t)(char, void*);
2022-11-19 14:53:58 +00:00
2022-12-17 11:43:29 +00:00
// Used to format anything that can fail (writing to C FILEs, etc...)
2022-11-30 11:36:21 +00:00
Result<usize> cstyle_format(const char* format, callback_t callback, void* arg, va_list ap);
2022-12-17 11:43:29 +00:00
// Used to format anything that cannot fail (formatting to a string, writing to the serial port (kernel-only))
usize pure_cstyle_format(const char* format, pure_callback_t callback, void* arg, va_list ap);
2022-12-17 11:43:29 +00:00
// Convenience function which outputs into a fixed-size buffer (not unlike vsnprintf)
usize vstring_format(char* buf, usize max, const char* format, va_list ap);
2022-12-17 11:43:29 +00:00
// Convenience function which outputs into a fixed-size buffer (not unlike snprintf)
2023-01-02 12:07:29 +00:00
usize string_format(char* buf, usize max, const char* format, ...) _format(3, 4);