File: netstring.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 (20 lines) | stat: -rw-r--r-- 630 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include "fmt.h"
#include "scan.h"
#include <assert.h>
#include <stdio.h>

int main() {
  char buf[100];
  char* s;
  size_t l;
  const char* orig;
  assert(fmt_netstring(buf,"hello world!",12)==16 && !memcmp(buf,"12:hello world!,",16));
  assert(scan_netstring(buf,16,&s,&l)==16 && s==buf+3 && l==12);

  orig="3:foo,"; assert(scan_netstring(orig,6,&s,&l)==6 && s==orig+2 && l==3);
  orig="4294967295:foo,"; assert(scan_netstring(orig,15,&s,&l)==0);
  orig="18446744073709551615:foo,"; assert(scan_netstring(orig,25,&s,&l)==0);

  assert(fmt_netstring(buf,orig,(size_t)-1)==0);
  assert(fmt_netstring(buf,NULL,(size_t)-1)==0);
}