From 2d798bd601e30e687422bb1b292b30756d2d2f88 Mon Sep 17 00:00:00 2001 From: Alex Lyon Date: Sun, 4 Mar 2018 18:07:38 -0800 Subject: [PATCH] expr, sync, whoami: update Oniguruma and winapi --- src/expr/Cargo.toml | 2 +- src/expr/syntax_tree.rs | 4 ++-- src/sync/Cargo.toml | 2 +- src/sync/sync.rs | 22 +++++++++++++--------- src/whoami/Cargo.toml | 2 +- src/whoami/platform/windows.rs | 7 +++++-- 6 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/expr/Cargo.toml b/src/expr/Cargo.toml index d182e7774..814a754d4 100644 --- a/src/expr/Cargo.toml +++ b/src/expr/Cargo.toml @@ -10,7 +10,7 @@ path = "expr.rs" [dependencies] libc = "0.2.26" -onig = "1.3.0" +onig = "3.1.1" uucore = { path="../uucore" } [[bin]] diff --git a/src/expr/syntax_tree.rs b/src/expr/syntax_tree.rs index bd7f3002c..904980360 100644 --- a/src/expr/syntax_tree.rs +++ b/src/expr/syntax_tree.rs @@ -13,7 +13,7 @@ //! use tokens::{Token}; -use onig::{Regex, Syntax, REGEX_OPTION_NONE}; +use onig::{Regex, RegexOptions, Syntax}; type TokenStack = Vec<(usize, Token)>; pub type OperandsList = Vec< Box >; @@ -354,7 +354,7 @@ fn infix_operator_and( values: &Vec ) -> Result { fn operator_match(values: &Vec) -> Result { assert!(values.len() == 2); - let re = match Regex::with_options(&values[1], REGEX_OPTION_NONE, Syntax::grep()) { + let re = match Regex::with_options(&values[1], RegexOptions::REGEX_OPTION_NONE, Syntax::grep()) { Ok(m) => m, Err(err) => return Err(err.description().to_string()) }; diff --git a/src/sync/Cargo.toml b/src/sync/Cargo.toml index 33ba4dfe9..22fcc2f82 100644 --- a/src/sync/Cargo.toml +++ b/src/sync/Cargo.toml @@ -11,7 +11,7 @@ path = "sync.rs" [dependencies] getopts = "0.2.14" libc = "0.2.26" -winapi = "0.2.8" +winapi = { version = "0.3", features = ["handleapi", "winerror"] } kernel32-sys = "0.2.2" uucore = { path="../uucore" } diff --git a/src/sync/sync.rs b/src/sync/sync.rs index 24b9d2c36..0457874d5 100644 --- a/src/sync/sync.rs +++ b/src/sync/sync.rs @@ -44,13 +44,17 @@ mod platform { extern crate kernel32; use std::{mem}; use std::fs::OpenOptions; - use std::io::{Write}; use std::os::windows::prelude::*; use uucore::wide::{FromWide, ToWide}; + use self::winapi::um::winbase; + use self::winapi::um::winnt; + use self::winapi::shared::minwindef; + use self::winapi::um::handleapi; + use self::winapi::shared::winerror; unsafe fn flush_volume(name: &str) { let name_wide = name.to_wide_null(); - if kernel32::GetDriveTypeW(name_wide.as_ptr()) == winapi::DRIVE_FIXED { + if kernel32::GetDriveTypeW(name_wide.as_ptr()) == winbase::DRIVE_FIXED { let sliced_name = &name[..name.len() - 1]; // eliminate trailing backslash match OpenOptions::new().write(true).open(sliced_name) { Ok(file) => if kernel32::FlushFileBuffers(file.as_raw_handle()) == 0 { @@ -61,10 +65,10 @@ mod platform { } } - unsafe fn find_first_volume() -> (String, winapi::HANDLE) { - let mut name: [winapi::WCHAR; winapi::MAX_PATH] = mem::uninitialized(); - let handle = kernel32::FindFirstVolumeW(name.as_mut_ptr(), name.len() as winapi::DWORD); - if handle == winapi::INVALID_HANDLE_VALUE { + unsafe fn find_first_volume() -> (String, winnt::HANDLE) { + let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = mem::uninitialized(); + let handle = kernel32::FindFirstVolumeW(name.as_mut_ptr(), name.len() as minwindef::DWORD); + if handle == handleapi::INVALID_HANDLE_VALUE { crash!(kernel32::GetLastError() as i32, "failed to find first volume"); } (String::from_wide_null(&name), handle) @@ -74,12 +78,12 @@ mod platform { let (first_volume, next_volume_handle) = find_first_volume(); let mut volumes = vec![first_volume]; loop { - let mut name: [winapi::WCHAR; winapi::MAX_PATH] = mem::uninitialized(); + let mut name: [winnt::WCHAR; minwindef::MAX_PATH] = mem::uninitialized(); if kernel32::FindNextVolumeW( - next_volume_handle, name.as_mut_ptr(), name.len() as winapi::DWORD + next_volume_handle, name.as_mut_ptr(), name.len() as minwindef::DWORD ) == 0 { match kernel32::GetLastError() { - winapi::ERROR_NO_MORE_FILES => { + winerror::ERROR_NO_MORE_FILES => { kernel32::FindVolumeClose(next_volume_handle); return volumes }, diff --git a/src/whoami/Cargo.toml b/src/whoami/Cargo.toml index 0768c0ee8..932df68ba 100644 --- a/src/whoami/Cargo.toml +++ b/src/whoami/Cargo.toml @@ -10,7 +10,7 @@ path = "whoami.rs" [dependencies] getopts = "0.2.14" -winapi = "0.2.8" +winapi = { version = "0.3", features = ["lmcons"] } advapi32-sys = "0.2.0" [dependencies.uucore] diff --git a/src/whoami/platform/windows.rs b/src/whoami/platform/windows.rs index d52c2b063..8014047a1 100644 --- a/src/whoami/platform/windows.rs +++ b/src/whoami/platform/windows.rs @@ -14,10 +14,13 @@ extern crate uucore; use std::io::{Error, Result}; use std::mem; use uucore::wide::FromWide; +use self::winapi::um::winnt; +use self::winapi::shared::lmcons; +use self::winapi::shared::minwindef; pub unsafe fn getusername() -> Result { - let mut buffer: [winapi::WCHAR; winapi::UNLEN as usize + 1] = mem::uninitialized(); - let mut len = buffer.len() as winapi::DWORD; + let mut buffer: [winnt::WCHAR; lmcons::UNLEN as usize + 1] = mem::uninitialized(); + let mut len = buffer.len() as minwindef::DWORD; if advapi32::GetUserNameW(buffer.as_mut_ptr(), &mut len) == 0 { return Err(Error::last_os_error()) }