Skip to content

Commit f1baaab

Browse files
committed
cdylib: use core instead of std
1 parent fafc7a8 commit f1baaab

File tree

1 file changed

+10
-13
lines changed
  • libz-rs-sys-cdylib/src

1 file changed

+10
-13
lines changed

libz-rs-sys-cdylib/src/gz.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ use crate::{
88
deflate, deflateEnd, deflateInit2_, deflateReset, inflate, inflateEnd, inflateInit2_,
99
inflateReset, z_off_t, z_stream, zlibVersion,
1010
};
11+
use core::cmp::Ordering;
1112
use core::ffi::{c_char, c_int, c_uint, c_void, CStr};
1213
use core::ptr;
1314
use libc::off_t;
1415
use libc::size_t; // FIXME: Switch to core::ffi::c_size_t when it's stable.
1516
use libc::{O_APPEND, O_CREAT, O_EXCL, O_RDONLY, O_TRUNC, O_WRONLY, SEEK_CUR, SEEK_END, SEEK_SET};
16-
use std::cmp;
17-
use std::cmp::Ordering;
1817
use zlib_rs::deflate::Strategy;
1918
use zlib_rs::MAX_WBITS;
2019

@@ -736,7 +735,7 @@ pub unsafe extern "C-unwind" fn gzbuffer(file: gzFile, size: c_uint) -> c_int {
736735
}
737736

738737
// Use a minimum buffer size of 8 to work with flush semantics elsewhere in the implementation.
739-
state.want = cmp::max(size, 8);
738+
state.want = Ord::max(size, 8);
740739

741740
0
742741
}
@@ -1064,14 +1063,14 @@ unsafe fn gz_read(state: &mut GzState, mut buf: *mut u8, mut len: usize) -> usiz
10641063
let mut got = 0;
10651064
loop {
10661065
// Set n to the maximum amount of len that fits in an unsigned int.
1067-
let mut n = cmp::min(len, c_uint::MAX as usize);
1066+
let mut n = Ord::min(len, c_uint::MAX as usize);
10681067

10691068
// First just try copying data from the output buffer. Note: The output
10701069
// buffer contains bytes that have been decompressed by `state.stream` and
10711070
// are waiting to be consumed - or, in direct mode, it contains bytes read
10721071
// directly from the underlying file descriptor.
10731072
if state.have != 0 {
1074-
n = cmp::min(n, state.have as usize);
1073+
n = Ord::min(n, state.have as usize);
10751074
// Safety:
10761075
// * n <= state.have, and there are `state.have` readable bytes starting
10771076
// at `state.next`.
@@ -1234,7 +1233,7 @@ unsafe fn gz_look(state: &mut GzState) -> Result<(), ()> {
12341233
&mut state.stream as *mut z_stream,
12351234
MAX_WBITS + 16,
12361235
zlibVersion(),
1237-
std::mem::size_of::<z_stream>() as i32,
1236+
core::mem::size_of::<z_stream>() as i32,
12381237
)
12391238
} != Z_OK
12401239
{
@@ -1632,7 +1631,7 @@ unsafe fn gz_write(state: &mut GzState, mut buf: *const c_void, mut len: usize)
16321631
}
16331632
// Safety: `state.stream.next_in` points into the buffer starting at `state.input`.
16341633
let have = unsafe { state.input_len() };
1635-
let copy = cmp::min(state.in_size.saturating_sub(have), len);
1634+
let copy = Ord::min(state.in_size.saturating_sub(have), len);
16361635
// Safety: The caller is responsible for ensuring that buf points to at least len readable
16371636
// bytes, and copy is <= len.
16381637
unsafe { ptr::copy(buf, state.input.add(have).cast::<c_void>(), copy) };
@@ -1659,7 +1658,7 @@ unsafe fn gz_write(state: &mut GzState, mut buf: *const c_void, mut len: usize)
16591658
let save_next_in = state.stream.next_in;
16601659
state.stream.next_in = buf.cast::<_>();
16611660
loop {
1662-
let n = cmp::min(len, c_uint::MAX as usize) as c_uint;
1661+
let n = Ord::min(len, c_uint::MAX as usize) as c_uint;
16631662
state.stream.avail_in = n;
16641663
state.pos += n as i64;
16651664
if gz_comp(state, Z_NO_FLUSH).is_err() {
@@ -1692,7 +1691,7 @@ fn gz_zero(state: &mut GzState, mut len: usize) -> Result<(), ()> {
16921691
// Compress `len` zeros.
16931692
let mut first = true;
16941693
while len != 0 {
1695-
let n = cmp::min(state.in_size, len);
1694+
let n = Ord::min(state.in_size, len);
16961695
if first {
16971696
// Safety: `state.input` is non-null here, either because it was initialized
16981697
// before this function was called (enabling the `state.stream.avail_in != 0`
@@ -2335,7 +2334,7 @@ pub unsafe extern "C-unwind" fn gzgets(file: gzFile, buf: *mut c_char, len: c_in
23352334
}
23362335

23372336
// Look for newline in current output buffer.
2338-
let mut n = cmp::min(left, state.have as _);
2337+
let mut n = Ord::min(left, state.have as _);
23392338
// Safety: `state.next` points to a block of `state.have` readable bytes. We're scanning
23402339
// the first `n` of those bytes, and `n <= state.have` based on the `min` calculation.
23412340
let eol = unsafe { libc::memchr(state.next.cast::<c_void>(), '\n' as c_int, n as _) };
@@ -2658,9 +2657,7 @@ unsafe extern "C-unwind" fn gzvprintf(
26582657
// A pointer to the space that can be used by `vsnprintf`. The size of the input buffer
26592658
// is `2 * state.in_size`, just for this function. That means we have at least
26602659
// `state.in_size` bytes available.
2661-
let next = (state.stream.next_in)
2662-
.add(state.stream.avail_in as usize)
2663-
.cast_mut();
2660+
let next = unsafe { (state.stream.next_in).add(state.stream.avail_in as usize) }.cast_mut();
26642661

26652662
// NOTE: zlib-ng writes a NULL byte to the last position of the input buffer. It must do so
26662663
// because in some cases it falls back to the `vsprintf` function, which contrary to

0 commit comments

Comments
 (0)