Sixty-five headers sat side by side in include/, so `#include "irq.h"` said nothing about where irq.h was or what it belonged to, and errno.h, stat.h and fcntl.h at the top shadowed the system's for any host tool built with -I./include. They are in folders now -- arch/ core/ fs/ dev/ gfx/ net/ uapi/ (and ldls/ for the Linux driver layer) -- and every include names the folder, as Linux's do: "core/proc.h". Done mechanically and checked the hard way: the kernel built from this tree disassembles identically to the one built from the tree before it. The full image boots, and userland is the same set of programs. Paths in docs and comments follow; docs/guides/layout.md has a table of what is where, and tools/fix-includes.py rewrites old-style includes from the folders in the tree, for code written before this. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01S1giNvrHTrPMPw7V6x1kQ4
82 lines
1.6 KiB
C
82 lines
1.6 KiB
C
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
//
|
|
// The bounded string builder. See include/core/sbuf.h for what it is and why it
|
|
// moved out of kernel/dev/procfs.c.
|
|
|
|
#include "core/types.h"
|
|
#include "core/sbuf.h"
|
|
|
|
void
|
|
sb_putc(struct sbuf *sb, char c)
|
|
{
|
|
if (sb->len < sb->cap - 1)
|
|
sb->p[sb->len++] = c;
|
|
}
|
|
|
|
void
|
|
sb_puts(struct sbuf *sb, const char *s)
|
|
{
|
|
while (*s)
|
|
sb_putc(sb, *s++);
|
|
}
|
|
|
|
void
|
|
sb_pad(struct sbuf *sb, const char *s, int width)
|
|
{
|
|
int n = 0;
|
|
while (s[n]) {
|
|
sb_putc(sb, s[n]);
|
|
n++;
|
|
}
|
|
while (n++ < width)
|
|
sb_putc(sb, ' ');
|
|
}
|
|
|
|
void
|
|
sb_puthex4(struct sbuf *sb, uint32 v)
|
|
{
|
|
static const char hex[] = "0123456789abcdef";
|
|
for (int i = 3; i >= 0; i--)
|
|
sb_putc(sb, hex[(v >> (i * 4)) & 0xF]);
|
|
}
|
|
|
|
void
|
|
sb_puthex(struct sbuf *sb, uint64 v, int digits)
|
|
{
|
|
static const char hex[] = "0123456789abcdef";
|
|
for (int i = digits - 1; i >= 0; i--)
|
|
sb_putc(sb, hex[(v >> (i * 4)) & 0xF]);
|
|
}
|
|
|
|
void
|
|
sb_putu(struct sbuf *sb, uint64 v)
|
|
{
|
|
char tmp[24];
|
|
int i = 0;
|
|
if (v == 0) { sb_putc(sb, '0'); return; }
|
|
while (v && i < (int)sizeof(tmp)) { tmp[i++] = '0' + (v % 10); v /= 10; }
|
|
while (i--) sb_putc(sb, tmp[i]);
|
|
}
|
|
|
|
void
|
|
sb_putu_pad(struct sbuf *sb, uint64 v, int width)
|
|
{
|
|
char tmp[24];
|
|
int i = 0, n;
|
|
|
|
if (v == 0) { tmp[i++] = '0'; }
|
|
while (v && i < (int)sizeof(tmp)) { tmp[i++] = '0' + (v % 10); v /= 10; }
|
|
for (n = i; n < width; n++)
|
|
sb_putc(sb, ' ');
|
|
while (i--)
|
|
sb_putc(sb, tmp[i]);
|
|
}
|
|
|
|
void
|
|
sb_kv(struct sbuf *sb, const char *label, uint64 v, const char *unit)
|
|
{
|
|
sb_puts(sb, label);
|
|
sb_putu(sb, v);
|
|
if (unit && *unit) { sb_putc(sb, ' '); sb_puts(sb, unit); }
|
|
sb_putc(sb, '\n');
|
|
}
|