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

#include <string.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 ;
}