skalibs

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

strn_fmt.c (461B)


      1 /* ISC license. */
      2 
      3 #include <skalibs/types.h>
      4 #include <skalibs/fmtscan.h>
      5 
      6 size_t strn_fmt (char *blah, char const *s, size_t len)
      7 {
      8   char *d = blah ;
      9   size_t i ;
     10   for (i = 0 ; i < len ; i++)
     11     if ((s[i] >= 32) && ((unsigned char)s[i] < 127)) *d++ = s[i] ;
     12     else
     13     {
     14       *d++ = '\\' ;
     15       *d++ = '0' ;
     16       *d++ = 'x' ;
     17       if ((unsigned char)s[i] < 16) *d++ = '0' ;
     18       d += uint_xfmt(d, (unsigned char)s[i]) ;
     19     }
     20   return d - blah ;
     21 }