summaryrefslogtreecommitdiff
path: root/bittorrent/mbtstr/include
diff options
context:
space:
mode:
authorMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
committerMartial Simon <msimon_fr@hotmail.com>2025-09-15 01:07:58 +0200
commit967be9e750221ab2ab783f95df79bb26d290a45e (patch)
tree6802900a5e975f9f68b169f0f503f040056d6952 /bittorrent/mbtstr/include
add: added projectsHEADmain
Diffstat (limited to 'bittorrent/mbtstr/include')
-rw-r--r--bittorrent/mbtstr/include/mbtstr/str.h30
-rw-r--r--bittorrent/mbtstr/include/mbtstr/utils.h17
-rw-r--r--bittorrent/mbtstr/include/mbtstr/view.h88
3 files changed, 135 insertions, 0 deletions
diff --git a/bittorrent/mbtstr/include/mbtstr/str.h b/bittorrent/mbtstr/include/mbtstr/str.h
new file mode 100644
index 0000000..aaea5d6
--- /dev/null
+++ b/bittorrent/mbtstr/include/mbtstr/str.h
@@ -0,0 +1,30 @@
+#ifndef MBTSTR_STR_H
+#define MBTSTR_STR_H
+
+////////////////////////////////////////////////////////////////////////////////
+/// THIS FILE WILL BE OVERWRITTEN ///
+////////////////////////////////////////////////////////////////////////////////
+
+// mbtutils
+#include <mbtstr/view.h>
+// libc
+#include <stdbool.h>
+
+struct mbt_str
+{
+ char *data;
+ size_t size;
+ size_t capacity;
+};
+
+bool mbt_str_ctor(struct mbt_str *str, size_t capacity) MBT_NONNULL(1);
+void mbt_str_dtor(struct mbt_str *str);
+
+struct mbt_str *mbt_str_init(size_t capacity);
+void mbt_str_free(struct mbt_str *str);
+
+bool mbt_str_pushc(struct mbt_str *str, char c) MBT_NONNULL(1);
+bool mbt_str_pushcstr(struct mbt_str *str, const char *cstr) MBT_NONNULL(1);
+bool mbt_str_pushcv(struct mbt_str *str, struct mbt_cview view) MBT_NONNULL(1);
+
+#endif /* !MBTSTR_STR_H */
diff --git a/bittorrent/mbtstr/include/mbtstr/utils.h b/bittorrent/mbtstr/include/mbtstr/utils.h
new file mode 100644
index 0000000..0bcbc79
--- /dev/null
+++ b/bittorrent/mbtstr/include/mbtstr/utils.h
@@ -0,0 +1,17 @@
+#ifndef MBTSTR_UTILS_H
+#define MBTSTR_UTILS_H
+
+////////////////////////////////////////////////////////////////////////////////
+/// THIS FILE WILL BE OVERWRITTEN ///
+////////////////////////////////////////////////////////////////////////////////
+
+// see the Attributes section in the subject
+#define MBT_ATTR(...) __attribute__((__VA_ARGS__))
+#define MBT_UNUSED MBT_ATTR(unused)
+#define MBT_PACKED MBT_ATTR(packed)
+#define MBT_NONNULL(...) MBT_ATTR(nonnull(__VA_ARGS__))
+#define MBT_RET_NONNULL MBT_ATTR(returns_nonnull)
+
+#define MBT_UNREACHABLE() __builtin_unreachable()
+
+#endif /* !MBTSTR_UTILS_H */
diff --git a/bittorrent/mbtstr/include/mbtstr/view.h b/bittorrent/mbtstr/include/mbtstr/view.h
new file mode 100644
index 0000000..dd6e196
--- /dev/null
+++ b/bittorrent/mbtstr/include/mbtstr/view.h
@@ -0,0 +1,88 @@
+#ifndef MBTSTR_VIEW_H
+#define MBTSTR_VIEW_H
+
+////////////////////////////////////////////////////////////////////////////////
+/// THIS FILE WILL BE OVERWRITTEN ///
+////////////////////////////////////////////////////////////////////////////////
+
+// mbtutils
+#include <mbtstr/utils.h>
+// libc
+#include <stdbool.h>
+#include <stdio.h>
+
+struct mbt_cview
+{
+ const char *data;
+ size_t size;
+};
+
+struct mbt_view
+{
+ char *data;
+ size_t size;
+};
+
+#define MBT_VIEW(Data, Size) \
+ ((struct mbt_view){ \
+ .data = (Data), \
+ .size = (Size), \
+ })
+
+// a "View" here is just any struct with a .data and a .size
+#define MBT_VIEW_OF(View) \
+ ((struct mbt_view){ \
+ .data = (View).data, \
+ .size = (View).size, \
+ })
+
+#define MBT_VIEW_ARR(Array) \
+ ((struct mbt_view){ \
+ .data = (Array), \
+ .size = sizeof((Array)), \
+ })
+
+// a "View" here is just any struct with a .data and a .size
+#define MBT_VIEW_SUB(View, Offset) \
+ ((struct mbt_view){ \
+ .data = (View).data + (Offset), \
+ .size = (View).size - (Offset), \
+ })
+
+#define MBT_CVIEW(Data, Size) \
+ ((struct mbt_cview){ \
+ .data = (Data), \
+ .size = (Size), \
+ })
+
+// a "View" here is just any struct with a .data and a .size
+#define MBT_CVIEW_OF(View) \
+ ((struct mbt_cview){ \
+ .data = (View).data, \
+ .size = (View).size, \
+ })
+
+#define MBT_CVIEW_LIT(Lit) \
+ ((struct mbt_cview){ \
+ .data = (Lit), \
+ .size = sizeof((Lit)) - 1, \
+ })
+
+#define MBT_CVIEW_ARR(Array) \
+ ((struct mbt_cview){ \
+ .data = (Array), \
+ .size = sizeof((Array)), \
+ })
+
+// a "View" here is just any struct with a .data and a .size
+#define MBT_CVIEW_SUB(View, Offset) \
+ ((struct mbt_cview){ \
+ .data = (View).data + (Offset), \
+ .size = (View).size - (Offset), \
+ })
+
+int mbt_cview_cmp(struct mbt_cview lhs, struct mbt_cview rhs);
+bool mbt_cview_contains(struct mbt_cview view, char c);
+void mbt_cview_fprint(struct mbt_cview view, FILE *stream) MBT_NONNULL(2);
+
+#endif /* !MBTSTR_VIEW_H */