skalibs

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

netstring_encode.c (452B)


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