summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--dynarr.h2
-rw-r--r--stdwrm.h8
-rw-r--r--str.h20
3 files changed, 21 insertions, 9 deletions
diff --git a/dynarr.h b/dynarr.h
index c9ce637..31b63a6 100644
--- a/dynarr.h
+++ b/dynarr.h
@@ -6,6 +6,8 @@
#include <string.h>
#include <err.h>
+#include "stdwrm.h"
+
typedef struct { size_t count, capacity; } DynArrHeader;
#define DYNARR(type) type *
diff --git a/stdwrm.h b/stdwrm.h
new file mode 100644
index 0000000..0b44a2b
--- /dev/null
+++ b/stdwrm.h
@@ -0,0 +1,8 @@
+#ifndef STDWRM_H
+#define STDWRM_H
+
+#ifdef STDWRM_IMPL
+#define STDWRM_STR_IMPL
+#endif
+
+#endif
diff --git a/str.h b/str.h
index c0fc626..7959488 100644
--- a/str.h
+++ b/str.h
@@ -2,6 +2,8 @@
#define STR_H
#include <string.h>
+
+#include "stdwrm.h"
#include "dynarr.h"
typedef DYNARR(char) string;
@@ -14,10 +16,10 @@ typedef struct {
#define strv(s) (strv_t) { s, strlen(s) }
string snew(void);
-size_t slen(const string *);
+size_t slen(const string);
void scats(string *, strv_t);
void scatc(string *, char);
-void sfree(string *);
+void sfree(string);
#ifdef STDWRM_STR_IMPL
@@ -28,28 +30,28 @@ string snew(void) {
return s;
}
-size_t slen(const string *s) {
- return DA_LEN(*s) - 1;
+size_t slen(const string s) {
+ return DA_LEN(s) - 1;
}
void scatc(string *s, char c) {
size_t n = DA_LEN(*s) + 1;
DA_FIT(*s, n);
- *s[n-2] = c;
- *s[n-1] = '\0';
+ (*s)[n-2] = c;
+ (*s)[n-1] = '\0';
DA_LEN(*s) = n;
}
void scats(string *s, strv_t sv) {
size_t n = DA_LEN(*s) + sv.n;
DA_FIT(*s, n);
- memcpy(&(*s)[slen(s)], sv.s, sv.n);
+ memcpy(&(*s)[slen(*s)], sv.s, sv.n);
(*s)[n-1] = '\0';
DA_LEN(*s) = n;
}
-void sfree(string *s) {
- DA_FREE(*s);
+void sfree(string s) {
+ DA_FREE(s);
}
#endif