Welcome to little lamb

Code » limb » commit a31d6b8

sa_coloff(): Add argument skip for when strings are..

author Olivier Brunel
2023-07-07 11:44:30 UTC
committer Olivier Brunel
2023-07-24 10:16:43 UTC
parent 3ef18faf2d0e1a58ed277e1d0d42090b4f205fd1

sa_coloff(): Add argument skip for when strings are..

.."prefixed" with a fixed-size blob.

src/doc/samisc.h/sa_coloff.3.md +4 -4
src/liblimb/include/limb/samisc.h +1 -1
src/liblimb/samisc.h/sa_coloff.c +2 -2
src/liblimb/samisc.h/sa_colptr.c +1 -1

diff --git a/src/doc/samisc.h/sa_coloff.3.md b/src/doc/samisc.h/sa_coloff.3.md
index 9d0f642..786ef94 100644
--- a/src/doc/samisc.h/sa_coloff.3.md
+++ b/src/doc/samisc.h/sa_coloff.3.md
@@ -10,20 +10,20 @@ sa_coloff - append an array of offsets to strings from an stralloc into it
     #include <limb/samisc.h>
 
 ```pre hl
-int sa_coloff(stralloc *<em>sa</em>, size_t <em>from</em>, size_t <em>end</em>)
+int sa_coloff(stralloc *<em>sa</em>, size_t <em>from</em>, size_t <em>skip</em>, size_t <em>end</em>)
 ```
 
 # DESCRIPTION
 
 The `sa_coloff`() function will scan the content of the given stralloc `sa`
 starting at offset `from`, expecting to find a succession of NUL-terminated
-strings, up to `end`. It will append into `sa` an array of offsets where each
-string is located within `sa->s`.
+strings after `skip` bytes, up to `end`. It will append into `sa` an array of
+offsets where each string is located within `sa->s` (not accounting for `skip`).
 
 ! INFO:
 ! The offsets added into `sa` are actually casted as *uintptr_t* so that they
 ! can later be turned into full string pointers (*char \**) if needed.
-! Such a conversion can be done using [sa_off2ptr](3).
+! Such a conversion can be done using [sa_off2ptr](3) if `skip` is 0.
 
 # RETURN VALUE
 
diff --git a/src/liblimb/include/limb/samisc.h b/src/liblimb/include/limb/samisc.h
index 30441f3..ec47f13 100644
--- a/src/liblimb/include/limb/samisc.h
+++ b/src/liblimb/include/limb/samisc.h
@@ -8,7 +8,7 @@
 #include <limb/stralloc.h>
 
 extern int  sa_patrim_put(stralloc *sa, u64 id, u64 u, const char *data);
-extern int  sa_coloff(stralloc *sa, size_t from, size_t end);
+extern int  sa_coloff(stralloc *sa, size_t from, size_t skip, size_t end);
 extern void sa_off2ptr(stralloc *sa, size_t arroff, size_t n);
 extern int  sa_colptr(stralloc *sa, size_t from, size_t end);
 
diff --git a/src/liblimb/samisc.h/sa_coloff.c b/src/liblimb/samisc.h/sa_coloff.c
index 169571b..8dacb80 100644
--- a/src/liblimb/samisc.h/sa_coloff.c
+++ b/src/liblimb/samisc.h/sa_coloff.c
@@ -5,7 +5,7 @@
 #include <limb/samisc.h>
 
 int
-sa_coloff(stralloc *sa, size_t from, size_t end)
+sa_coloff(stralloc *sa, size_t from, size_t skip, size_t end)
 {
     size_t salen = sa->len;
     int ret = 0;
@@ -16,7 +16,7 @@ sa_coloff(stralloc *sa, size_t from, size_t end)
             return -1;
         }
 
-        off += strlen(sa->s + off) + 1;
+        off += skip + strlen(sa->s + off + skip) + 1;
         ++ret;
     }
 
diff --git a/src/liblimb/samisc.h/sa_colptr.c b/src/liblimb/samisc.h/sa_colptr.c
index 25b295d..f0e2e54 100644
--- a/src/liblimb/samisc.h/sa_colptr.c
+++ b/src/liblimb/samisc.h/sa_colptr.c
@@ -9,7 +9,7 @@ sa_colptr(stralloc *sa, size_t from, size_t end)
     size_t arroff = sa->len;
     /* first collect the offsets from sa->s, as relocation might happen as we
      * grow sa to store the array */
-    int n = sa_coloff(sa, from, end);
+    int n = sa_coloff(sa, from, 0, end);
     if (n < 0)
         return n;
     /* then turn offsets into pointers */