File: scan_long.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 (31 lines) | stat: -rw-r--r-- 895 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
21
22
23
24
25
26
27
28
29
30
31
#include "scan.h"
#include "fmt.h"
#include "buffer.h"
#include <assert.h>

int main() {
  char buf[1024];
  unsigned long long int i;
  unsigned long l;
  if (sizeof(unsigned long)==4) {
    assert(scan_ulong("4294967295",&l) == 10 && l==4294967295ul);
    assert(scan_ulong("4294967296",&l) == 9 && l==429496729);
  } else {
    assert(scan_ulong("18446744073709551615",&l) == 20 && l==18446744073709551615ull);
    assert(scan_ulong("18446744073709551616",&l) == 19 && l==1844674407370955161ull);
  }
  if (sizeof(unsigned long) != 4)
    return 0;
  for (i=1; i<0xfffffffffull; i+=i+1) {
    int k;
    unsigned long test;
    buf[k=fmt_ulonglong(buf,i)]=0;
    buffer_puts(buffer_1,buf); buffer_putnlflush(buffer_1);
    if (buf[scan_ulong(buf,&test)])
      /* scan did not like the whole number */
      assert(i>0xffffffffull);
    else
      assert(i<=0xffffffffull);
  }
  return 0;
}