aboutsummaryrefslogtreecommitdiff
path: root/src/polyfill.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/polyfill.c')
-rw-r--r--src/polyfill.c19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/polyfill.c b/src/polyfill.c
new file mode 100644
index 0000000..f7db312
--- /dev/null
+++ b/src/polyfill.c
@@ -0,0 +1,19 @@
+#include "jurl.h"
+
+#ifdef POLYFILL_CBYTES
+const char* janet_getcbytes(const Janet *argv, int32_t n) {
+ JanetByteView view = janet_getbytes(argv, n);
+ const char *cstr = (const char *)view.bytes;
+ if (strlen(cstr) != (size_t) view.len) {
+ janet_panic("bytes contain embedded 0s");
+ }
+ return cstr;
+}
+
+const char *janet_optcbytes(const Janet *argv, int32_t argc, int32_t n, const char *dflt) {
+ if (n >= argc || janet_checktype(argv[n], JANET_NIL)) {
+ return dflt;
+ }
+ return janet_getcbytes(argv, n);
+}
+#endif