diff --git a/src/bin/hexyl.rs b/src/bin/hexyl.rs index a9e8bb9..de87204 100644 --- a/src/bin/hexyl.rs +++ b/src/bin/hexyl.rs @@ -93,10 +93,10 @@ fn run() -> Result<(), Box> { None => Input::Stdin(stdin.lock()), }; - let skip_arg = matches.value_of("skip"); + let skip_arg = matches.value_of("skip").and_then(parse_hex_or_int); - if let Some(length) = skip_arg.and_then(parse_hex_or_int) { - reader.seek(SeekFrom::Start(length))?; + if let Some(skip) = skip_arg { + reader.seek(SeekFrom::Start(skip))?; } let length_arg = matches.value_of("length").or(matches.value_of("bytes")); @@ -124,7 +124,7 @@ fn run() -> Result<(), Box> { let display_offset = matches .value_of("display_offset") .and_then(parse_hex_or_int) - .unwrap_or(0); + .unwrap_or(skip_arg.unwrap_or(0)); let stdout = io::stdout(); let mut stdout_lock = stdout.lock(); diff --git a/src/input.rs b/src/input.rs index 4de746b..fd54d14 100644 --- a/src/input.rs +++ b/src/input.rs @@ -18,10 +18,21 @@ impl<'a> Read for Input<'a> { impl<'a> Seek for Input<'a> { fn seek(&mut self, pos: SeekFrom) -> io::Result { match *self { - Input::File(ref mut file) => file.seek(pos), + Input::File(ref mut file) => { + let seek_res = file.seek(pos); + if let Err(Some(29)) = seek_res.as_ref().map_err(|err| err.raw_os_error()) { + return Err(io::Error::new( + io::ErrorKind::Other, + "Using '--seek' is not supported when using a pipe", + ) + .into()); + }; + dbg!(&seek_res); + seek_res + } Input::Stdin(_) => Err(io::Error::new( io::ErrorKind::Other, - "not supported by stdin-input", + "Using '--seek' is not supported when reading from STDIN", )), } }