File: scan_tofrom_array.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 (18 lines) | stat: -rw-r--r-- 538 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "str.h"
#include "array.h"
#include "textcode.h"

size_t scan_tofrom_array(size_t (*func)(const char*,char*,size_t*),
			        array* src,array* dest) {
  size_t scanned;
  size_t needed;
  char* x;
  array_cat0(src);
  if (array_failed(src) || array_failed(dest)) return 0;
  needed=array_bytes(src);
  x=((char*)array_start(dest))+array_bytes(dest);
  if (!array_allocate(dest,1,array_bytes(dest)+needed-1)) return 0;
  needed=func(array_start(src),x,&scanned);
  array_truncate(src,1,array_bytes(src)-1);
  return needed;
}