code wiki / _hdl_build / _flatedecode_authored.nx

_flatedecode_authored.nx source

↩ module page · 16 lines · 829 B

1// AUTHORED BY THE NISHI BUILDER (flatedecode template) -- zlib/FlateDecode wrapper over the inflate lib 2import "_inflate_lib_authored.nx" 3func flate_decode(src: *u8, srclen: i64, out: *u8) -> i64 { 4 if ((src[0] as i64) & 0x0f) != 8 { return 0 - 1 } 5 return inflate(((src as i64)+2) as *u8, srclen-2, out) 6} 7func main() -> i64 { 8 let lz: *i64=sys_mmap(8) as *i64; let z: *u8=sys_read_file("/tmp/fd.zlib" as *u8, lz) 9 let lo: *i64=sys_mmap(8) as *i64; let orig: *u8=sys_read_file("/tmp/fd.orig" as *u8, lo) 10 if (z as i64)==0 { sys_exit(2) } if (orig as i64)==0 { sys_exit(2) } 11 let out: *u8=sys_mmap(65536) 12 let n: i64=flate_decode(z, lz[0], out) 13 var ok: i64=1; if n!=lo[0] { ok=0 } var i: i64=0; while i<lo[0] { if out[i]!=orig[i] { ok=0 } i=i+1 } 14 if ok==1 { sys_exit(0) } sys_exit(1) 15 return 1 16}