summaryrefslogtreecommitdiff
path: root/kernel/timer.c
diff options
context:
space:
mode:
authorAnton Kling <anton@kling.gg>2024-12-14 15:33:06 +0100
committerAnton Kling <anton@kling.gg>2024-12-14 15:33:06 +0100
commit0495bfb0d64bb2b318b629fd1c821dc8e2c8647d (patch)
tree960e72aadc18f3ec0899dd69781c9ba55b5ef944 /kernel/timer.c
parent6179308e3f6e4c64013e5db5da9b30a22abca704 (diff)
sb/printf: Add ksbprintf
Easier to add formatted strings to the string builder without using intermediate buffers.
Diffstat (limited to 'kernel/timer.c')
-rw-r--r--kernel/timer.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/kernel/timer.c b/kernel/timer.c
index 6321cda..2cfd714 100644
--- a/kernel/timer.c
+++ b/kernel/timer.c
@@ -47,11 +47,13 @@ u64 timer_get_ms(void) {
}
int clock_read(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {
- if (0 != offset) {
- return 0;
- }
+ struct sb ctx;
+ sb_init_buffer(&ctx, buffer, len);
+ sb_set_ignore(&ctx, offset);
+
u64 r = timer_get_ms();
- return min(len, (u64)kbnprintf(buffer, len, "%llu", r));
+ (void)ksbprintf(&ctx, "%llu", r);
+ return sv_length(SB_TO_SV(ctx));
}
int clock_write(u8 *buffer, u64 offset, u64 len, vfs_fd_t *fd) {