shithub: sl

Download patch

ref: c3f03656e3fb201ea8165fe773529c4cb4dea930
parent: 1d5710a5c982ad26dfb127a76af30a69bc42856f
author: spew <spew@cbza.org>
date: Sat Apr 12 16:29:45 EDT 2025

lsd: read multiple strings

--- a/src/plan9/lsd.sl
+++ b/src/plan9/lsd.sl
@@ -171,11 +171,18 @@
 (defcval c-float float)
 (defcval c-double double)
 
-(def (c-str loc)
-  "Read the null-terminated string at the pointer location"
-  (unless coref (error "not attached to proc"))
-  (io-seek coref (c-ptr (@ loc)))
-  (str-trim (io-readuntil coref 0) "" "\x00"))
+(def (c-str loc (n NIL))
+  «Read the null-terminated strings at the pointer location.
+
+   Examples:
+       (c-str (c-ptr "argv") (c-int "argc")); read the args.»
+  (def (readstr loc)
+    (unless coref (error "not attached to proc"))
+    (io-seek coref loc)
+    (str-trim (io-readuntil coref 0) "" "\x00"))
+  (if n
+      (vec-map readstr (c-ptr (@ loc) n))
+      (readstr (c-ptr (@ loc)))))
 
 (def (@ loc)
   «Return the address of local or global data.