skalibs

Mirror/fork of https://skarnet.org/software/skalibs/
git clone https://ccx.te2000.cz/git/skalibs
Log | Files | Refs | README | LICENSE

netstring_append.c (488B)


      1 /* ISC license. */
      2 
      3 #include <string.h>
      4 #include <skalibs/uint64.h>
      5 #include <skalibs/stralloc.h>
      6 #include <skalibs/netstring.h>
      7 
      8 int netstring_appendb (stralloc *sa, char const *s, size_t len)
      9 {
     10   char fmt[UINT64_FMT] ;
     11   size_t n = uint64_fmt(fmt, len) ;
     12   if (!stralloc_readyplus(sa, len + n + 2)) return 0 ;
     13   fmt[n] = ':' ;
     14   memcpy(sa->s + sa->len, fmt, n+1) ;
     15   memcpy(sa->s + sa->len + n+1, s, len) ;
     16   sa->s[sa->len + n+1 + len] = ',' ;
     17   sa->len += n + 2 + len ;
     18   return 1 ;
     19 }