File: buffer_get_token_sa.c

package info (click to toggle)
libowfat 0.34-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,288 kB
  • sloc: ansic: 20,181; makefile: 16
file content (23 lines) | stat: -rw-r--r-- 462 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
#include "byte.h"
#include "stralloc.h"
#include "buffer.h"
#include <errno.h>

int buffer_get_token_sa(buffer* b,stralloc* sa,
			const char* charset,
			size_t setlen) {
  for (;;) {
    char x;
    if (!stralloc_readyplus(sa,1)) goto nomem;
    switch  (buffer_getc(b,&x)) {
    case -1: return -1;
    case 0: return 0;
    }
    stralloc_append(sa,&x);
    if (byte_chr(charset,setlen,x)<setlen) break;
  }
  return 1;
nomem:
  errno=ENOMEM;
  return -1;
}