aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/buf.h31
-rw-r--r--src/buf.c28
2 files changed, 59 insertions, 0 deletions
diff --git a/include/buf.h b/include/buf.h
new file mode 100644
index 0000000..a49e0fa
--- /dev/null
+++ b/include/buf.h
@@ -0,0 +1,31 @@
1// buf.h --- buffer -*- C -*-
2//
3// Copyright (c) 2026 Martin Michalec <martin@michalec.dev>
4//
5// SPDX-License-Identifier: MIT
6//
7// This file is part of COSMOS Codebase.
8//
9// Commentary:
10//
11// Code:
12
13#ifndef INCLUDED_COSMOS_BUF_H
14#define INCLUDED_COSMOS_BUF_H
15
16#include "types.h"
17
18struct buf {
19 u8 *beg;
20 u8 *ptr;
21 u8 *end;
22};
23
24struct buf buf_from (void *beg, void *ptr, void *end);
25struct buf buf_from_mb (struct mb);
26
27#define DBG_ASSERT_BUF(buf) /* TODO(cmmm): implement */
28
29#endif // INCLUDED_COSMOS_BUF_H
30
31// buf.h ends here
diff --git a/src/buf.c b/src/buf.c
new file mode 100644
index 0000000..70b66ad
--- /dev/null
+++ b/src/buf.c
@@ -0,0 +1,28 @@
1// buf.c --- buffer -*- C -*-
2//
3// Copyright (c) 2026 Martin Michalec <martin@michalec.dev>
4//
5// SPDX-License-Identifier: MIT
6//
7// This file is part of COSMOS Codebase.
8//
9// Commentary:
10//
11// Code:
12
13#include "buf.h"
14#include "dbg.h"
15
16struct buf
17buf_from (void *beg, void *ptr, void *end)
18{
19 return (struct buf) { .beg = beg, .ptr = ptr, .end = end };
20}
21
22struct buf
23buf_from_mb (struct mb mb)
24{
25 return buf_from (mb.ptr, mb.ptr, MB_END (mb));
26}
27
28// buf.c ends here