duskos

dusk os fork
git clone git://git.alexwennerberg.com/duskos
Log | Files | Refs | README | LICENSE

commit 3199ff5d43e2c0a52e6428b91f81189ff50dd96d
parent 966859f51ed5db55a6fe362d08deb50db10f9cf5
Author: Virgil Dupras <hsoft@hardcoded.net>
Date:   Tue, 20 Sep 2022 19:19:33 -0400

lib/crc: fix algo and add crc32<<

Diffstat:
Mfs/lib/crc.c | 4++--
Mfs/lib/crc.fs | 7++++++-
2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/fs/lib/crc.c b/fs/lib/crc.c @@ -1,13 +1,13 @@ extern unsigned int crc32(unsigned int crc, int c) { unsigned int i, b; + crc = crc ^ c; for (i=0; i<8; i++) { - b = (c ^ crc) & 1; + b = crc & 1; crc >>= 1; if (b) { crc = crc ^ $EDB88320; } - c >>= 1; } return crc; } diff --git a/fs/lib/crc.fs b/fs/lib/crc.fs @@ -5,4 +5,9 @@ cc<< lib/crc.c \ Computes CRC32 over range "a u". : crc32[] ( a u -- crc ) - swap >r >r -1 begin ( n ) 8b to@+ V1 crc32 next -1 xor rdrop ; + swap >r >r -1 begin ( n ) 8b to@+ V1 crc32 next ^ rdrop ; + +: crc32<< ( -- crc ) + word curpath :find# Path :open -1 begin ( hdl crc ) + over IO :getc dup 0>= while crc32 repeat + drop swap IO :close ( ~crc ) ^ ;