Cksum new_io

This commit is contained in:
Camille TJHOA
2015-04-23 23:52:45 +02:00
parent f7a95688ed
commit a7caf3c86a
2 changed files with 7 additions and 7 deletions
File diff suppressed because one or more lines are too long
+6 -6
View File
@@ -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;