summaryrefslogtreecommitdiff
path: root/src/libstddjb/string_unquote.c
blob: d22f46d285426051057ae12d5123dc071a6291ee (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/* ISC license. */

#include <string.h>
#include <errno.h>
#include <skalibs/skamisc.h>

int string_unquote (char *d, size_t *w, char const *s, size_t len, size_t *r)
{
  if (!len-- || (*s++ != '"')) return (errno = EINVAL, 0) ;
  {
    size_t rr, ww ;
    char tmp[len ? len : 1] ;
    if (!string_unquote_withdelim(tmp, &ww, s, len, &rr, "\"", 1)) return 0 ;
    if (rr == len) return (errno = EPIPE, 0) ;
    memcpy(d, tmp, ww) ;
    *w = ww ;
    *r = rr + 2 ;
  }
  return 1 ;
}