summaryrefslogtreecommitdiff
path: root/src/libstddjb/stralloc_insertb.c
blob: f964ea56a21c9917412f255b439967519ebe58a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
/* ISC license. */

#include <sys/types.h>
#include <errno.h>
#include <skalibs/stralloc.h>

int stralloc_insertb (stralloc *sa, size_t offset, char const *s, size_t n)
{
  if (offset > sa->len) return (errno = EINVAL, 0) ;
  if (!stralloc_readyplus(sa, n)) return 0 ;
  memmove(sa->s + offset + n, sa->s + offset, sa->len - offset) ;
  sa->len += n ;
  memmove(sa->s + offset, s, n) ;
  return 1 ;
}