From faaa9a40ecb38b46dea79c2e8b26244d2a4223bd Mon Sep 17 00:00:00 2001 From: Lukas Lueg Date: Mon, 5 Aug 2019 20:19:43 +0200 Subject: [PATCH] Remove byteorder-dependency --- Cargo.toml | 1 - src/terminfo/parser/compiled.rs | 18 ++++++++++++------ src/win.rs | 8 ++++---- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 04c6e105..65b5d15e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -20,7 +20,6 @@ travis-ci = { repository = "Stebalien/term" } appveyor = { repository = "Stebalien/term" } [dependencies] -byteorder = "1.2.1" dirs = "2.0.1" [target.'cfg(windows)'.dependencies] diff --git a/src/terminfo/parser/compiled.rs b/src/terminfo/parser/compiled.rs index 04bfd01d..d84e21b0 100644 --- a/src/terminfo/parser/compiled.rs +++ b/src/terminfo/parser/compiled.rs @@ -14,8 +14,6 @@ use std::collections::HashMap; use std::io; use std::io::prelude::*; -use byteorder::{LittleEndian, ReadBytesExt}; - use crate::terminfo::Error::*; use crate::terminfo::TermInfo; use crate::Result; @@ -26,11 +24,14 @@ pub use crate::terminfo::parser::names::*; // sure if portable. fn read_le_u16(r: &mut dyn io::Read) -> io::Result { - r.read_u16::().map(u32::from) + let mut buf = [0; 2]; + r.read_exact(&mut buf) + .map(|()| u32::from(u16::from_le_bytes(buf))) } fn read_le_u32(r: &mut dyn io::Read) -> io::Result { - r.read_u32::() + let mut buf = [0; 4]; + r.read_exact(&mut buf).map(|()| u32::from_le_bytes(buf)) } fn read_byte(r: &mut dyn io::Read) -> io::Result { @@ -50,7 +51,9 @@ pub fn parse(file: &mut dyn io::Read, longnames: bool) -> Result { }; // Check magic number - let magic = file.read_u16::()?; + let mut buf = [0; 2]; + file.read_exact(&mut buf)?; + let magic = u16::from_le_bytes(buf); let read_number = match magic { 0x011A => read_le_u16, @@ -131,7 +134,10 @@ pub fn parse(file: &mut dyn io::Read, longnames: bool) -> Result { let string_map: HashMap<&str, Vec> = if string_offsets_count > 0 { let string_offsets = (0..string_offsets_count) - .map(|_| file.read_u16::()) + .map(|_| { + let mut buf = [0; 2]; + file.read_exact(&mut buf).map(|()| u16::from_le_bytes(buf)) + }) .collect::>>()?; let mut string_table = Vec::new(); diff --git a/src/win.rs b/src/win.rs index 2c8f147c..8fd7f5ad 100644 --- a/src/win.rs +++ b/src/win.rs @@ -13,14 +13,14 @@ // FIXME (#13400): this is only a tiny fraction of the Windows console api use crate::color; -use std::io; -use std::io::prelude::*; -use std::ops::Deref; -use std::ptr; use crate::Attr; use crate::Error; use crate::Result; use crate::Terminal; +use std::io; +use std::io::prelude::*; +use std::ops::Deref; +use std::ptr; use winapi::shared::minwindef::{DWORD, WORD}; use winapi::um::consoleapi::{GetConsoleMode, SetConsoleMode};