ref: 3ca4aafa0234e3c056d128767f384c602462170b
parent: 123ae8f453ef8add7d8abe42975066ec15f81a57
author: Ori Bernstein <ori@eigenstate.org>
date: Thu Jan 15 13:47:08 EST 2015
add cstrconvp for when all you have is a C char* Some APIs don't give a C string length for a byte buffer. As unsafe as that may be, accomodate them.
--- a/libstd/cstrconv.myr
+++ b/libstd/cstrconv.myr
@@ -1,5 +1,8 @@
+use "types.use"
+
pkg std =
const cstrconv : (buf : byte[:] -> byte[:])
+ const cstrconvp : (p : byte# -> byte[:])
;;
const cstrconv = {buf
@@ -11,4 +14,15 @@
;;
;;
-> buf
+}
+
+const cstrconvp = {p
+ var i, base
+
+ i = 0
+ base = p castto(intptr)
+ while ((base + i) castto(byte#))# != 0
+ i++
+ ;;
+ -> p[:i]
}