skalibs

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

stralloc_insertb.c (398B)


      1 /* ISC license. */
      2 
      3 #include <string.h>
      4 #include <errno.h>
      5 #include <skalibs/stralloc.h>
      6 
      7 int stralloc_insertb (stralloc *sa, size_t offset, char const *s, size_t n)
      8 {
      9   if (offset > sa->len) return (errno = EINVAL, 0) ;
     10   if (!stralloc_readyplus(sa, n)) return 0 ;
     11   memmove(sa->s + offset + n, sa->s + offset, sa->len - offset) ;
     12   sa->len += n ;
     13   memmove(sa->s + offset, s, n) ;
     14   return 1 ;
     15 }