mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
Cksum new_io
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -8,27 +8,27 @@
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
use std::old_io as io;
|
||||
use std::fs::OpenOptions;
|
||||
use std::io::Write;
|
||||
|
||||
static CRC_TABLE_LEN: usize = 256;
|
||||
|
||||
fn main() {
|
||||
let mut table = Vec::with_capacity(CRC_TABLE_LEN);
|
||||
for num in range(0, CRC_TABLE_LEN) {
|
||||
for num in (0 .. CRC_TABLE_LEN) {
|
||||
table.push(crc_entry(num as u8) as u32);
|
||||
}
|
||||
let mut file = io::File::open_mode(&Path::new("crc_table.rs"), io::Truncate, io::Write).unwrap();
|
||||
let output = format!("/* auto-generated (DO NOT EDIT) */
|
||||
let file = OpenOptions::new().truncate(true).write(true).open("crc_table.rs").ok().unwrap();
|
||||
write!(&file, "/* auto-generated (DO NOT EDIT) */
|
||||
|
||||
pub static CRC_TABLE: [u32; {}] = {:?};", CRC_TABLE_LEN, table);
|
||||
file.write_line(output.as_slice()).unwrap();
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn crc_entry(input: u8) -> u32 {
|
||||
let mut crc = (input as u32) << 24;
|
||||
|
||||
for _ in range(0, 8) {
|
||||
for _ in (0 .. 8) {
|
||||
if crc & 0x80000000 != 0 {
|
||||
crc <<= 1;
|
||||
crc ^= 0x04c11db7;
|
||||
|
||||
Reference in New Issue
Block a user