Skip to content

Commit

Permalink
Fixes for windows
Browse files Browse the repository at this point in the history
  • Loading branch information
bjorn3 committed Nov 6, 2024
1 parent cef00c2 commit 0ae2eaf
Showing 1 changed file with 35 additions and 9 deletions.
44 changes: 35 additions & 9 deletions bzip2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,9 @@ use libbzip2_rs_sys::bzlib::{
};

use libc::{
_exit, close, exit, fchmod, fchown, fclose, fdopen, ferror, fflush, fgetc, fileno, fopen,
fprintf, fread, free, fwrite, getenv, isatty, lstat, malloc, open, perror, remove, rewind,
signal, size_t, stat, strcat, strcmp, strcpy, strlen, strncmp, strncpy, strstr, ungetc,
utimbuf, utime, write, FILE,
_exit, close, exit, fclose, fdopen, ferror, fflush, fgetc, fileno, fopen, fprintf, fread, free,
fwrite, getenv, isatty, malloc, open, perror, remove, rewind, signal, size_t, stat, strcat,
strcmp, strcpy, strlen, strncmp, strncpy, strstr, ungetc, utimbuf, write, FILE,
};
extern "C" {
static mut stdin: *mut FILE;
Expand Down Expand Up @@ -1526,10 +1525,11 @@ unsafe fn fopen_output_safely(mut name: *mut c_char, mut mode: *const libc::c_ch
}
fp
}
#[cfg(unix)]
unsafe fn notAStandardFile(mut name: *mut c_char) -> Bool {
let mut i: IntNative = 0;
let mut statBuf: stat = zeroed();
i = lstat(name, &mut statBuf);
i = libc::lstat(name, &mut statBuf);
if i != 0 as libc::c_int {
return 1 as Bool;
}
Expand All @@ -1538,15 +1538,35 @@ unsafe fn notAStandardFile(mut name: *mut c_char) -> Bool {
}
1 as Bool
}
#[cfg(not(unix))]
unsafe fn notAStandardFile(mut name: *mut c_char) -> Bool {
let Ok(name) = std::ffi::CStr::from_ptr(name).to_str() else {
return 1;
};
let Ok(metadata) = std::path::Path::new(name).symlink_metadata() else {
return 1;
};

if metadata.file_type().is_file() {
0
} else {
1
}
}
#[cfg(unix)]
unsafe fn countHardLinks(mut name: *mut c_char) -> i32 {
let mut i: IntNative = 0;
let mut statBuf: stat = zeroed();
i = lstat(name, &mut statBuf);
i = libc::lstat(name, &mut statBuf);
if i != 0 as libc::c_int {
return 0 as libc::c_int;
}
(statBuf.st_nlink).wrapping_sub(1) as i32
}
#[cfg(not(unix))]
unsafe fn countHardLinks(mut name: *mut c_char) -> i32 {
0 // FIXME
}
static mut fileMetaInfo: stat = unsafe { zeroed() };
unsafe fn saveInputFileMetaInfo(mut srcName: *mut c_char) {
let mut retVal: IntNative = 0;
Expand All @@ -1555,6 +1575,7 @@ unsafe fn saveInputFileMetaInfo(mut srcName: *mut c_char) {
ioError();
}
}
#[cfg(unix)]
unsafe fn applySavedTimeInfoToOutputFile(mut dstName: *mut c_char) {
let mut retVal: IntNative = 0;
let mut uTimBuf: utimbuf = utimbuf {
Expand All @@ -1563,19 +1584,24 @@ unsafe fn applySavedTimeInfoToOutputFile(mut dstName: *mut c_char) {
};
uTimBuf.actime = fileMetaInfo.st_atime;
uTimBuf.modtime = fileMetaInfo.st_mtime;
retVal = utime(dstName, &uTimBuf);
retVal = libc::utime(dstName, &uTimBuf);
if retVal != 0 as libc::c_int {
ioError();
}
}
#[cfg(not(unix))]
unsafe fn applySavedTimeInfoToOutputFile(_dstName: *mut c_char) {}
#[cfg(unix)]
unsafe fn applySavedFileAttrToOutputFile(mut fd: IntNative) {
let mut retVal: IntNative = 0;
retVal = fchmod(fd, fileMetaInfo.st_mode);
retVal = libc::fchmod(fd, fileMetaInfo.st_mode);
if retVal != 0 as libc::c_int {
ioError();
}
fchown(fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid);
libc::fchown(fd, fileMetaInfo.st_uid, fileMetaInfo.st_gid);
}
#[cfg(not(unix))]
unsafe fn applySavedFileAttrToOutputFile(_fd: IntNative) {}
unsafe fn containsDubiousChars(_: *mut c_char) -> Bool {
0
}
Expand Down

0 comments on commit 0ae2eaf

Please sign in to comment.