aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cstring/include/cstring.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/cstring/include/cstring.h b/cstring/include/cstring.h
index 9425d51..75a5388 100644
--- a/cstring/include/cstring.h
+++ b/cstring/include/cstring.h
@@ -4,6 +4,7 @@
4#include <assert.h> 4#include <assert.h>
5#include <bsd/string.h> 5#include <bsd/string.h>
6#include <stdbool.h> 6#include <stdbool.h>
7#include <stdio.h>
7 8
8/// A fixed-size string. 9/// A fixed-size string.
9/// The string is null-terminated so that it can be used with the usual C APIs. 10/// The string is null-terminated so that it can be used with the usual C APIs.
@@ -90,6 +91,14 @@
90 \ 91 \
91 static inline bool STRING##_eq_cstr(STRING a, const char* b) { \ 92 static inline bool STRING##_eq_cstr(STRING a, const char* b) { \
92 return (a.length == strlen(b)) && strncmp(a.str, b, a.length) == 0; \ 93 return (a.length == strlen(b)) && strncmp(a.str, b, a.length) == 0; \
94 } \
95 \
96 static inline STRING STRING##_itoa(int n) { \
97 STRING str = (STRING){0}; \
98 const int written = snprintf(str.str, SIZE, "%d", n); \
99 assert(written >= 0); \
100 str.length = (size_t)written; \
101 return str; \
93 } 102 }
94 103
95DEF_STRING(sstring, 32) // Small. 104DEF_STRING(sstring, 32) // Small.